淺淺談密碼學 2018/12/27
我恨你 我愛你
基本用語 明文(Plain text) 密文(Cipher text) 加密(Encryption) 解密(Decryption) 加密金鑰(Encryption Key) 解密金鑰(Decryption Key)
This is a book. Ek TFhfifsf ifsf af bfofofkf. Dk This is a book.
密碼學 Cryptography 使密文最難被破解
加密法 Encryption Substitution cipher AES Calculus SHA-1 Hash DES linear algebra Caesar cipher MD5 Hash Discrete mathematics
凱薩加密法 Caesar cipher
a b c d ………… x y z a b c d ………… x y z
密碼表 a b c d ………… x y z z a b c ………… w x y
NBNQQMJQUDTZ 密碼表 解密 I WILL HELP YOU 明文 A B C D E F G H I J K L M N O P R S T U … 密文 V W X Y NBNQQMJQUDTZ 解密 I WILL HELP YOU
把英文移動幾位來當密碼表 英文移動26次就會回到原位 只有26種密碼表 破解? 找26次最像文章的那個就對了
NBNQQMJQUDTZ 位移5位
strlist = list(change) strlist_decry = strlist i = 0 import os def decryption(): str1 = input("請輸入密文:") for k in range(26): change = str1.lower() strlist = list(change) strlist_decry = strlist i = 0 while i < len(strlist): if ord(strlist[i]) >= 97+k: strlist_decry[i] = chr(ord(strlist[i]) - k) else: strlist_decry[i] = chr(ord(strlist[i]) + 26 - k) i = i+1 print ("解密結果為:"+"".join(strlist_decry)) decryption() ymfsp%dtz&&
替換加密法 Substitution cipher
Abccd! E fg Ahah. Hello! I am Hihi . 加密 密碼表 明文 H e l o I a m i 密文 b c
A bc Mama. Eman an b ibe. I bc Mimi. Emin in b ibe. 明文 密文 i a A bc Mama. Eman an b ibe. a b m c I bc Mimi. Emin in b ibe. s n I am Mimi. Emin in a iae. t e h m I am Hihi. Emis is a iae. c、b i I am Hihi. This is a iat. I am Hihi. This is a cat. I am Hihi. This is a bat.
Abccd. E fg f xelc. E cbflm f ndlo “zbdzcb gdqmrfem zbdzcb vbf” Abccd ! E fg f xelc. E cbflm f ndlo “zbdzcb gdqmrfem zbdzcb vbf”. Dmb ofk E fvjbo gt wdkasebmo. Adn rd vfk zbdzcb gdqmrfem zbdzcb vbf em Bmxceva ? Ab vheo “gdqmrfem zbdzcb gdqmrfem vbf”. Gdqmrfem zbdzcb gdqmrfem vbf? Abccd ! I fg f xilc. I cbflm f ndlo “zbdzcb gdqmrfim zbdzcb vbf”. Dmb ofk I fvjbo gt wdkasibmo. Adn rd vfk zbdzcb gdqmrfim zbdzcb vbf im Bmxciva ? Ab vhio “gdqmrfim zbdzcb gdqmrfim vbf”. Gdqmrfim zbdzcb gdqmrfim vbf? 常使用: e a t i o X
常使用: e a t i o X X Abccd ! I ag a xilc. I cbalm a ndlo “zbdzcb gdqmraim zbdzcb vba”. Dmb oak I avjbo gt wdkasibmo. Adn rd vak zbdzcb gdqmraim zbdzcb vba im Bmxciva ? Ab vhio “gdqmraim zbdzcb gdqmraim vba”. Gdqmraim zbdzcb gdqmraim vba? Abccd ! I am a xilc. I cbalm a ndlo “zbdzcb mdqmraim zbdzcb vba”. Dmb oak I avjbo mt wdkasibmo. Adn rd vak zbdzcb mdqmraim zbdzcb vba im Bmxciva ? Ab vhio “mdqmraim zbdzcb mdqmraim vba”. Mdqmraim zbdzcb mdqmraim vba?
Hbcco. I am a xilc. I cbalm a wolo “zbozcb moqmraim zbozcb vba” Hbcco ! I am a xilc. I cbalm a wolo “zbozcb moqmraim zbozcb vba”. Omb oak I avjbo mt wokhsibmo. How ro vak zbozcb mdqmraim zbdzcb vba im Bmxcivh ? Hb vhio “moqmraim zbozcb moqmraim vba”. Moqmraim zbozcb moqmraim vba? Hbcco ! I am a xilc. I cbalm a wolo “zbozcb moqmraim zbozcb vba”. Omb oak I avjbo mt wokhsibmo. How ro vak zbozcb mdqmraim zbdzcb vba im Bmxcivh ? Hb vhio “moqmraim zbozcb moqmraim vba”. Moqmraim zbozcb moqmraim vba? Hbcco ! I am a xilc. I cbalm a wolo “zbozcb moqmtaim zbozcb vba”. Omb oak I avjbo mt wokhsibmo. How to vak zbozcb mdqmtaim zbozcb vba im Bmxcivh ? Hb vhio “moqmtaim zbozcb moqmtaim vba”. Moqmraim zbozcb moqmraim vba?
Hello. I am a xilc. I lealm a wolo “zeozle moqmtaim zeozle vea” Hello ! I am a xilc. I lealm a wolo “zeozle moqmtaim zeozle vea”. Ome oak I avjbo mt wokhsiemo. How to vak zeozle mdqmtaim zeozle vea im Emxlivh ? Hb vhio “moqmtaim zeozle moqmtaim vea”. Moqmraim zeozle moqmraim vea ? Hello ! I am a xilc. I lealm a wolo “zeozle moqmtaim zeozle vea”. Ome oak I avjbo mt wokhsiemo. How to vak zeozle mdqmtaim zeozle vea im Emxlivh ? Hb vhio “moqmtaim zeozle moqmtaim vea”. Moqmraim zeozle moqmraim vea ?
He said “mountain people mountain sea”. mountain people mountain sea? 明文 h e l o i a m v c k y r n w d p u t 密文 b f g j z q s 明文 y f s b g 密文 t u v w x Hello ! I am a girl. I learn a word “people mountain people sea”. One day I asked my boyfriend. How to say people mountain people sea in English ? He said “mountain people mountain sea”. mountain people mountain sea?
Base64
基於64個可列印字元來表示二進位資料的表示方法。由於2^6=64 以每6個位元為一個單元。
ASCII 0010 0000 (space) 二進位 圖形 0100 0001 A 0110 0001 a 0100 0010 B 0100 0001 A 0110 0001 a 0100 0010 B 0110 0010 b 0100 0011 C 0110 0011 c 0100 0100 D 0110 0100 d 0100 0101 E 0110 0101 e 0100 0110 F 0110 0110 f 0100 0111 G 0110 0111 g 0100 1000 H 0110 1000 h 0100 1001 I 0110 1001 i 0100 1010 J 0110 1010 j 0100 1011 K 0110 1011 k 0100 1100 L 0110 1100 l 0100 1101 M 0110 1101 m 0100 1110 N 0110 1110 n 0100 1111 O 0110 1111 o 0101 0000 P 0111 0000 p 0101 0001 Q 0111 0001 q 0101 0010 R 0111 0010 r 0101 0011 S 0111 0011 s 0101 0100 T 0111 0100 t 0101 0101 U 0111 0101 u 0101 0110 V 0111 0110 v 0101 0111 W 0111 0111 w 0101 1000 X 0111 1000 x 0101 1001 Y 0111 1001 y 0101 1010 Z 0111 1010 z ASCII 0010 0000 (space)
Base64索引表 數值 字元 A 16 Q 32 g 48 w 1 B 17 R 33 h 49 x 2 C 18 S 34 i 50 y A 16 Q 32 g 48 w 1 B 17 R 33 h 49 x 2 C 18 S 34 i 50 y 3 D 19 T 35 j 51 z 4 E 20 U 36 k 52 5 F 21 V 37 l 53 6 G 22 W 38 m 54 7 H 23 X 39 n 55 8 I 24 Y 40 o 56 9 J 25 Z 41 p 57 10 K 26 a 42 q 58 11 L 27 b 43 r 59 12 M 28 c 44 s 60 13 N 29 d 45 t 61 14 O 30 e 46 u 62 + 15 P 31 f 47 v 63 / Base64索引表
t h e 1 29 6 33 37 d G h i
編碼的位元組數不能被3整除先使用0位元組值在末尾補足,使其能夠被3整除 “=”代表補足的位元組數
i S 1 26 23 12 a X M =
I am Hihi 編碼 SSBhbSBIaWhp
Good job 編碼 R29vZCBqb2I=
初衷 滿足電子郵件中不能直接使用非ASCII碼字符的規定 電子郵件 效率高,複雜程度小
Thank you!