CTF之加解密总结
0x01 Base64
Base64顾名思义就是用64个可显示字符表示所有的ASC字符,64也就是6Bits,而ASC字符一共有256个,也就是8Bits。Base64编码要求把3个8位字节(38=24)转化为4个6位的字节(46=24),之后在6位的前面补两个0,形成8位一个字节的形式。 如果剩下的字符不足3个字节,则用0填充,输出字符使用’=’,因此编码后输出的文本末尾可能会出现1或2个’=’
内存1个字符占8位例如
转前: s 1 3先转成ascii:对应 115 49 512进制: 01110011 00110001 001100116个一组(4组) 011100110011000100110011然后才有后面的 011100 110011 000100 110011然后计算机是8位8位的存数 6不够,自动就补两个高位0了所有有了 高位补0科学计算器输入 00011100 00110011 00000100 00110011得到 28 51 4 51查对下照表 c z E z
形式
ZXZhbCgkX1BPU1RbcDRuOV96MV96aDNuOV9qMXVfU2gxX0oxM10pNTU2NJC3ODHHYWJIZ3P4ZWY=
0x02 Base32
Base32和Base64相比只有一个区别就是,用32个字符表示256个ASC字符,也就是说5个ASC字符一组可以生成8个Base字符。注:以上两种编码都可以使用python的base64模块来加解密
0x03 培根密码
培根密码,培根所用的密码是一种本质上用二进制数设计的,没有用通常的0和1来表示,而是采用a和b
密文形式是明显两个不同的字符。如大写字母和小写字母,英文和数字,斜体和正体。例如
DEath IS JUST A PaRT oF lIFE,sOMeTHInG wE'RE aLL dESTInED TO dO.是大写小写两个不同的字符大写用a表示,小写用b表示选取5个一组DEath aabbb ISJUS aaaaa TAPaR aaaba ToFlI ababa FEsOM aabaa eTHIn baaab GwERE abaaa aLLdE baabaSTInE aaaba DTOdO aaab按照上述的形式去在表里找对应得明文.
第一种方式
A aaaaa B aaaab C aaaba D aaabb
E aabaa F aabab G aabba H aabbb I abaaa J abaab K ababa L ababb M abbaa N abbab O abbba P abbbb Q baaaa R baaab S baaba T baabb U babaa V babab W babba X babbb Y bbaaa Z bbaab第二种方式
a AAAAA g AABBA n ABBAA t BAABA
b AAAAB h AABBB o ABBAB u-v BAABB c AAABA i-j ABAAA p ABBBA w BABAA d AAABB k ABAAB q ABBBB x BABAB e AABAA l ABABA r BAAAA y BABBA f AABAB m ABABB s BAAAB z BABBB0x04
摩尔斯电码是一种早期的数字化通信形式,但是它不同于现代只使用零和一两种状态的二进制代码,它的代码包括五种: 点、划、点和划之间的停顿、每个字符间短的停顿(在点和划之间)、每个词之间中等的停顿以及句子之间长的停顿。
形如:– — .-. … . 解密对照下图摩斯密码表:0x05 JsFuck
JSFuck 可以让你只用 6 个字符 !+ 来编写 JavaScript 程序。
[][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+ []]]]][([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+([]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])+[[+!+[]]]][+[[+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]+(![]+[])[+[[+[]]]]+([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+[+!+[]]+([][([]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+([]+[])[+[[!+[]+!+[]]]]+(![]+[])[+[[+[]]]]+(![]+[])[+[[!+[]+!+[]+!+[]]]]+(![]+[])[+[[+!+[]]]]]+[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]])()其他的一些表达:
false => [] true => ![] undefined => [][[]] NaN => +[[]] 0 => +[] 1 => +!+[] 2 => !+[]+!+[] 10 => [+!+[]]+[+[]] Array => [] Number => +[] String => []+[] Boolean => [] Function => []["filter"] eval => []["filter"]() window => []["filter"]() 可以使用firebug直接解密.0x06 栅栏密码
所谓栅栏密码,就是把要加密的明文分成N个一组,然后把每组的第1个字连起来,形成一段无规律的话。 不过栅栏密码本身有一个潜规则,就是组成栅栏的字母一般不会太多。(一般不超过30个,也就是一、两句话)
例如
明文:THERE IS A CIPHER去掉空格后变为:THEREISACIPHER两个一组,得到:TH ER EI SA CI PH ER先取出第一个字母:TEESCPE再取出第二个字母:HRIAIHR连在一起就是:TEESCPEHRIAIHR还原为所需密码。而解密的时候,我们先把密文从中间分开,变为两行:T E E S C P EH R I A I H R再按上下上下的顺序组合起来:THEREISACIPHER分出空格,就可以得到原文了:THERE IS A CIPHER例如密文:NlEyQd{seft}N l E y Q d { s e f t }NEQ{etIydsf}