첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ 카이사르 암호법을 사용하는 방법을 보여준다.

 

▶ 예제 코드 (PY)

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)
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요