Ask Your Question
0

error in decoding shift cryptosystem

asked 3 years ago

SKUN gravatar image

updated 2 years ago

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))
Preview: (hide)

Comments

Is it a homework?

Max Alekseyev gravatar imageMax Alekseyev ( 3 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 2 years ago

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)
Preview: (hide)
link

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: 3 years ago

Seen: 247 times

Last updated: Aug 27 '22