Posted onEdited onInctfViews: Disqus: Word count in article: 858Reading time ≈3 mins.
note
Encodings
ASCII
ASCII is a 7-bit encoding standard which allows the representation of
text using the integers 0-127.
1 2 3
arr = [99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125] result = "".join(chr(x) for x in arr) print(result)
1 2
❯ python encoding.py crypto{ASCII_pr1nt4bl3}
crypto{ASCII_pr1nt4bl3}
Hex
Hexadecimal can be used to represent ASCII strings. First each letter
is converted to an ordinal number according to the ASCII table. Then the
decimal numbers are converted to base-16 numbers.
1 2 3
a = 0x63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d result = bytes.fromhex(hex(a)[2:]).decode() print(result)
Base64 allows us to represent binary data as an ASCII string using an
alphabet of 64 characters.
1 2 3 4
import base64 h = '72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf' a = base64.b64encode(bytes.fromhex(h)) print(a.decode())
1
crypto/Base+64+Encoding+is+Web+Safe/
crypto/Base+64+Encoding+is+Web+Safe/
Bytes and Big Integers
Cryptosystems like RSA works on numbers, but messages are made up of
characters. The most common way is to take the ordinal bytes of the
message, convert them into hexadecimal, and concatenate.
1 2 3 4
from Crypto.Util.number import * enc = "11515195063862318899931685488813747395775516287289682636499965282714637259206269" result = long_to_bytes(int(enc)).decode() print(result)
# FLAG ^ K1 ^ K2 ^ K3 ^ K1 ^ (K2 ^ K3) = FLAG k1_k2_k3 = xor(bytes.fromhex(KEY1), bytes.fromhex(KEY2_KEY3)) FLAG = xor(bytes.fromhex(FLAG_K1_K2_K3), k1_k2_k3) print(FLAG.decode())
crypto{x0r_i5_ass0c1at1v3}
Favourite byte
XOR with a single secret byte.
1 2 3 4 5 6
from pwn import xor data = bytes.fromhex("73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d") for i inrange(256): res = xor(data, i) ifb"crypto"in res: print(res.decode())
crypto{0x10_15_my_f4v0ur173_by7e}
You either know, XOR you
don't
Brute-forcing the key using the known flag format
crypto{.