Added Lab2/Lab3 IS
This commit is contained in:
parent
011d5aded1
commit
0755dd4b76
6 changed files with 109 additions and 140 deletions
|
@ -2,20 +2,19 @@ def main():
|
|||
shift = (ord('C') - ord('y')) % 26
|
||||
|
||||
ctext = "XVIEWYWI"
|
||||
plaintext = ""
|
||||
plaintext = []
|
||||
|
||||
for char in ctext:
|
||||
if char.isalpha():
|
||||
shifted = ord(char.lower()) - shift
|
||||
if shifted < ord('a'):
|
||||
shifted += 26
|
||||
plaintext += chr(shifted)
|
||||
for ch in ctext:
|
||||
if ch.isalpha():
|
||||
base = ord('a')
|
||||
shifted = (ord(ch.lower()) - base - shift) % 26 + base
|
||||
plaintext.append(chr(shifted))
|
||||
else:
|
||||
plaintext += char
|
||||
plaintext.append(ch)
|
||||
|
||||
print(f"Attack type: Known plaintext attack")
|
||||
print(f"Ciphertext: {ctext}")
|
||||
print(f"Decrypted: {plaintext}")
|
||||
print(f"Decrypted: {''.join(plaintext)}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue