■ 카이사르 암호법을 사용하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
SHIFT = 1 def Encrypt(plainText): encryptedTest = "" global SHIFT for plainCharacter in plainText: encryptedTest += chr(ord(plainCharacter) + SHIFT) return encryptedTest def Decrypt(encryptedText): plainText = "" global SHIFT for encryptedCharacter in encryptedText: plainText += chr(ord(encryptedCharacter) - SHIFT) return plainText plainText = "python is powerful" encryptedText = Encrypt(plainText) decryptedText = Decrypt(encryptedText) print(plainText) print(encryptedText) print(decryptedText) |