Modified Lab 1 IS
This commit is contained in:
parent
fdc634b589
commit
933a52b3a8
8 changed files with 166 additions and 384 deletions
|
@ -1,6 +1,7 @@
|
|||
## ptext = plaintext
|
||||
## ctext = ciphertext
|
||||
## mk = multiplicative key
|
||||
## ak = additive key
|
||||
from collections import defaultdict
|
||||
|
||||
def add_cipher_en(ptext, ak):
|
||||
result = ""
|
||||
|
@ -76,6 +77,10 @@ def affine_de(ctext, ak, mk):
|
|||
result += chr((((ord(ch) - 97 - ak) * inverse) % 26) + 97)
|
||||
return result
|
||||
|
||||
def mult_inverse(mk):
|
||||
inverse = pow(mk, -1, 26)
|
||||
return inverse
|
||||
|
||||
def operator(argument,ptext,ak,mk):
|
||||
match argument:
|
||||
case '1':
|
||||
|
@ -91,6 +96,7 @@ def operator(argument,ptext,ak,mk):
|
|||
print("Multiplicative Key: ", mk)
|
||||
ctext = mult_cipher_en(ptext, mk)
|
||||
print("Ciphertext: ", ctext)
|
||||
print("Multiplicative Inverse: ", mult_inverse(mk))
|
||||
print("Decrypted Text: ", mult_cipher_de(ctext, mk))
|
||||
case '3':
|
||||
print("Affine Cipher")
|
||||
|
@ -99,6 +105,7 @@ def operator(argument,ptext,ak,mk):
|
|||
print("Multiplicative Key: ", mk)
|
||||
ctext = affine_en(ptext, ak, mk)
|
||||
print("Ciphertext: ", ctext)
|
||||
print("Affine Inverse: ", mult_inverse(mk))
|
||||
print("Decrypted Text: ", affine_de(ctext, ak, mk))
|
||||
case '4':
|
||||
print("Goodbye")
|
||||
|
@ -122,6 +129,5 @@ def main():
|
|||
op = input("Enter your choice of operation: ")
|
||||
operator(op, ptext, ak, mk)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue