Do you know Atsuhiko Nakata's Youtube University? Recently, I got a desire to watch smart videos, I often see it, but among the many videos, about "encryption" There was something that was being taught.
If you haven't seen it yet, I highly recommend it. I enjoyed watching it even though I had no knowledge of cryptography. You can see it from the link below. https://www.youtube.com/watch?v=7dSVR_zuJJs&t=694s
So, in that video, there was a word that really impressed me. so! There was ** "Caesar Cryptography"! It was the word ** w
As far as I can tell, the alphabetical order is shifted by a few minutes to make a sentence. I found out that this is a cryptographic rule.
For example When the word apple is applied to the Caesar code, it becomes "fuuqj".
When I was listening to this story, my brain intuitively thought that it would be difficult to decipher. I was issuing an alert, but for the time being, I am also an engineer.
I was wondering how to do it if I wrote it with this encryption actual program, so I actually made it. It was easier than I expected. .. ..
After doing that, I noticed that the alphabet is There are 27 in total. In other words, there are only 26 patterns that can be used for encryption. There are 52 ways including left and right. I realized that this encryption method is quite low level. .. .. ..
There seems to be a more complicated Caesar encryption method, The cryptographic method that simply shifts the order of the alphabet by N I found it better to stop.
I have never used it, In the future, I will use it for my relatives. w
import string
#######################################
#Caesar crypto complex
def decrypt_caesar(encrypt_text, gap=1):
decrypt_text = ''
for c in encrypt_text:
number = string.ascii_lowercase.index(c)
decrypt_text += string.ascii_lowercase[number - gap]
return decrypt_text
encrypt_text = 'fuuqj'
for i in range(len(string.ascii_lowercase)):
text = decrypt_caesar(encrypt_text, i)
print(text)
#######################################
#Caesar cipher
def encrypt_caesar(decrypt_text, gap=1):
encrypt_text = ''
for c in decrypt_text:
number = string.ascii_lowercase.index(c)
search_text = string.ascii_lowercase*2
encrypt_text += search_text[number + gap]
return encrypt_text
#Caesar cipher
print(encrypt_caesar('apple', 5))
Recommended Posts