ROT13은 굉장히 단순한 암호알고리즘이다. Rotate by 13의 약자이며 13자리 뒤로 밀어내는 고대 카이사르 암호의 일종이다.
ROT의 종류는 ROT13, ROT26, ROT47이 있다.
ROT26은 평문인데..이게왜...ㅋㅋ..
우선 알파멧은 기본적으로 A-Z 까지 26개가 있다.
이것을 13개씩 쪼개면 A-M까지와 N-Z가 나오는데 각 위치에 맞는 순서끼리 서로 치환하는 것이다.
a -> n
b -> o
이렇게 서로 치환된다.
$python3 -c 'import string; print(" ".join(list(string.ascii_lowercase)[:13]))'
a b c d e f g h i j k l m
$python3 -c 'import string; print(" ".join(list(string.ascii_lowercase)[13:]))'
n o p q r s t u v w x y z
"""
a b c d e f g h i j k l m
CONVERT
n o p q r s t u v w x y z
"""
ROT13 을 구현할 수 있는 방법은 LINUX 의 tr 을 사용하거나 Python으로 작성하는 방법 두가지가 있다.
아래는 tr로 구현한 모습이다. tr 뒤에 문자들은 정규식이다.
// 변환 전
$python3 -c 'import string; print(" ".join(list(string.ascii_lowercase)[13:]))'
n o p q r s t u v w x y z
// 변환 후
$python3 -c 'import string; print(" ".join(list(string.ascii_lowercase)[13:]))' | tr [A-Za-z] [N-ZA-Mn-za-m]
a b c d e f g h i j k l m
두번쨰로는 Python이다 물론 직접 구현해도 좋지만, 파이썬의 장점. 즉 생산성을 생각하면 이미 builtiin되어있는 것을 이용하는것도 좋다.
// Python One-Line
$python3 -c 'import codecs; print(codecs.encode("n o p q r s t u v w x y z", "rot13"))'
a b c d e f g h i j k l m
// Python Normal
import codecs
print(codecs.encode("INPUT-YOUR-STRING", 'rot13'))
결과적으로 one-line에 모든것을 해결하려하면 이렇게 된다.
$python3 -c 'import string; print(" ".join(list(string.ascii_lowercase)[13:]))' | xargs -I argv python3 -c 'import codecs; print(codecs.encode("argv", "rot13"))'
a b c d e f g h i j k l m
'Cyrpto > Computer Science' 카테고리의 다른 글
CRYPTO - Base64 Encoding Mechanism (1) | 2022.10.04 |
---|