Added Lab2/Lab3 IS

This commit is contained in:
sherlock 2025-08-12 09:43:39 +05:30
parent 011d5aded1
commit 0755dd4b76
6 changed files with 109 additions and 140 deletions

View file

@ -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()