crypto入门小知识
crypto加密类型简介
ASCII
ASCII is a 7-bit encoding standard which allows the representation of text using the integers 0-127.
我们可以通过python的chr和ord对其在ASCII和密钥之间转化
Hex
对于一串16进制编码,it is something more user-friendly and portable across different systems.
我们可以通过bytes.fromhex()和hex()对其在HEX和密钥之间转化
Base64
One character of a Base64 string encodes 6 bits, and so 4 characters of Base64 encode three 8-bit bytes.
python输入指令前需要import base64
我们可以通过base64.b64encode()和base64.b64decode()之间转化
例:
给出一串 72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf
先对其进行bytes.fromhex()转化,得到
b’r\xbc\xa9\xb6\x8f\xc1j\xc7\xbe\xeb\x8f\x84\x9d\xca\x1d\x8ax>\x8a\xcf\x96y\xbf\x92i\xf7\xbf’
再输入base64.b64encode()
得到最终的flag为 b’crypto/Base+64+Encoding+is+Web+Safe/‘
Bytes and Big Integers
对于RSA加密,习惯上先对一段密文进行bytes_to_long()加密,得到一串数字
python使用指令前需要from Crypto.Util.number import *
我们通过long_to_bytes()和bytes_to_long()在数字和密钥之间转化
XOR Starter
For longer binary numbers we XOR bit by bit
我们可以通过首先将每个字符转换为代表 Unicode 字符的整数来 XOR 字符串
XOR在python中表示为 ^
下图为XOR的几条运算律
Quadratic Residues
We say that an integer
x
is a Quadratic Residue if there exists ana
such thata2 = x mod p
. If there is no such solution, then the integer is a Quadratic Non-Residue.
If
a2 = x
then (-a)2 = x. So ifx
is a quadratic residue in some finite field, then there are always two solutions fora
.