scientific-programming-exer.../exam/ex19/main.py

22 lines
998 B
Python
Raw Normal View History

2019-02-23 22:24:42 +00:00
from caesar import caesar
from statistical_attack import get_statistical_key
text1 = "hello world this is a test"
text2 = "this is a message that is obfuscated"
K2 = 4
K1 = 13
print(caesar(text1, K1))
print(caesar(caesar(text1, K1), K1))
print(caesar(text2, K2))
print(caesar(caesar(text2, K2), abs(K2 - 26)))
text4 = "In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence"
text4 = "".join((s for s in text4 if s in " abcdefghijklmnopqrstuvwxyz"))
print(get_statistical_key(caesar(text4, K2)))
print(get_statistical_key(caesar(text2, K2)))