Ask Your Question
0

error in decoding shift cryptosystem

asked 2022-04-04 20:30:56 +0200

SKUN gravatar image

updated 2022-08-27 10:50:48 +0200

FrédéricC gravatar image

I want to shift backward to decrypt, but when I write k=-7, it it error that k is outside of range, so how can I correct it?

shift_system = ShiftCryptosystem(AlphabeticStrings())
message = "The shift cryptosystem generalizes the Caeser cipher"
plaintext = shift_system.encoding(message)
print("plaintext:", plaintext)
key = 7
encode = shift_system(key)
ciphertext = encode(plaintext)
print("ciphertext:", ciphertext)
decode = shift_system(shift_system.inverse_key(key))
print("Decoding ciphertext gives plaintext?", plaintext == decode(ciphertext))
edit retag flag offensive close merge delete

Comments

Is it a homework?

Max Alekseyev gravatar imageMax Alekseyev ( 2022-04-05 23:26:54 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2022-08-25 08:14:20 +0200

dantetante gravatar image

You have to read the docs! You don't use enciphering and deciphering. The decryption is not the same as encoding, which you are doing twice. Use

c=shift_system.enciphering(key,plaintext)

and then for going back:

plaintextagain=shift_system.deciphering(key,c)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2022-04-04 20:30:56 +0200

Seen: 179 times

Last updated: Aug 27 '22