ENCODING
ASCII is a 7-bit encoding standard which allows the representation of text using the integers 0-127.
Using the below integer array, convert the numbers to their corresponding ASCII characters to obtain a flag.
ASCII = 7비트 인코딩
아래 정수 배열로 숫자를 ASCII로 변환해 플래그를 얻어라
In Python, the chr() function can be used to convert an ASCII ordinal number to a character (the ord() function does the opposite.
chr() ord()를 쓰면 되는데, chr은 ASCII 서수를 문자로 ord는 문자를 서수로 바꾸어준다.
이 문제에선 chr 함수를 써야하는걸 알 수 있다.
[99, 114, 121, 112, 116, 111, 123, 65, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125]
s = [99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125]
for a in s:
print(chr(a),end="")
해석해보면 리스트를 변수에 넣고
for 함수를 사용해서 리스트값을 하나하나 서수를 문자로 변환해 a에 넣고 end를 이용해 하나의 값으로 출력한것
crypto{ASCII_pr1nt4bl3}
HEX
When we encrypt something the resulting ciphertext commonly has bytes which are not printable ASCII characters. If we want to share our encrypted data, it's common to encode it into something more user-friendly and portable across different systems.
Hexadecimal can be used in such a way to represent ASCII strings. First each letter is converted to an ordinal number according to the ASCII table (as in the previous challenge). Then the decimal numbers are converted to base-16 numbers, otherwise known as hexadecimal. The numbers can be combined together, into one long hex string.
Included below is a flag encoded as a hex string. Decode this back into bytes to get the flag.
무언가를 암호화 할때 암호문에는 일반적으로
인쇄가능한 ASCII 문자가 아닌 바이트라는게 있다
이 문제는 16진수 문자열로 인코딩된 플래그가 포함 되있다
이걸 바이트로 다시 디코딩 해서 플래그 찾으셈
In Python, the bytes.fromhex() function can be used to convert hex to bytes. The .hex() instance method can be called on byte strings to get the hex representation\
이럴때 bytes.fromhex() 함수를 사용해서
16진수 바이트로 변환 할수 있음
.hex() 는 바이트 문자열에서 호출 되어서 16진수 표현을 얻을수있다함
63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6
a = "63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d"
print(bytes.fromhex(a))
bytes.fromhex를 이용해서 16진수로 표현된 문자열 a을 바이트로 변환 시켜서 출력시킨것이다
crypto{You_will_be_working_with_hex_strings_a_lot}
BASE64
Another common encoding scheme is Base64, which allows us to represent binary data as an ASCII string using an alphabet of 64 characters. One character of a Base64 string encodes 6 binary digits (bits), and so 4 characters of Base64 encode three 8-bit bytes.
Base64 is most commonly used online, so binary data such as images can be easily included into HTML or CSS files.
Take the below hex string, decode it into bytes and then encode it into Base64
인코딩 체계에
base64 라고 64자의 알파벳을 사용해서 이진데이터를
ASCII 문자열로 나타낼수 있다
base64 문자열의 한 문자는 6개의 이진수를 인코딩하므로,
base64의 4문자는 3개의 8비트 바이트를 인코딩한다
온라인에서 일반적으로 사용되서 이미지와 같은 이진 데이터를
HTML 또는 CSS 파일에 쉽게 포함할수 있음
아래 16진수 문자열을 바이트로 디코딩 하고 Base64로 인코딩 해라
In Python, after importing the base64 module with import base64, you can use the base64.b64encode() function. Remember to decode the hex first as the challenge description states.
import base64로 모듈을 가져오고
base64.b64encode()
함수를 사용 할 수 있다
먼저 16진수먼저 인코딩 해라(해독)
72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf
일단 16진수를 어떻게 해야할지 생각해보고 있었는데 아까 decoding 할때 썼던 bytes.fromhex를 사용하면 될거같다 근데
16진수를 먼저 해독하고 모듈을 또 사용해서 답을 하나를 만들어야 하니까 result 사용하면 되겠다 라고 생각했는데 딱히 필요가 없었다
import base64
a = "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf"
b = bytes.fromhex(a)
print(base64.b64encode(b))
import base64로 base64 모듈을 가져와서
a변수에 문제 넣고
b변수에서 a를 16진수를 바이트로 해독해주고
결국에 b에들어있는건 바이트 a
그걸 base64.b64encode 출력할때 저 함수를 적용 시켜버리면
crypto/Base+64+Encoding+is+Web+Safe/
Bytes and Big integers
Cryptosystems like RSA works on numbers, but messages are made up of characters. How should we convert our messages into numbers so that mathematical operations can be applied?
The most common way is to take the ordinal bytes of the message, convert them into hexadecimal, and concatenate. This can be interpreted as a base-16/hexadecimal number, and also represented in base-10/decimal.
RSA와 같은 암호 시스템은 숫자로 작동하지만 메시지는 문자로 구성
수학 연산을 적용할 수 있도록 메시지를 숫자로 어떻게 변환하는
가장 일반적인 방법은
메시지의 서수 바이트를 가져와 16진수로 변환하고 연결하는 것
이는 16진수/16진수로 해석할 수 있으며 10진수/10진수로도 표시
Python's PyCryptodome library implements this with the methods bytes_to_long() and long_to_bytes(). You will first have to install PyCryptodome and import it with from Crypto.Util.number import *
Python의 PyCryptodome 라이브러리는 bytes_to_long() 및 long_to_bytes() 메서드로 이를 구현합니다. 먼저 PyCryptodome을 설치하고 from Crypto.Util.number import *로 가져와야 합니다.
해석을 들어보니 모듈을 설치하고 그 안에서 선언 (import)를
한 뒤에
코드를 짜는것이엿다
from Crypto.Util.number import *
a = "label"
for i in range(len(a)):
s = ord(a[i])
b = s^13
print(chr(b))
a
l
o
h
a
라고 나온다
플래그 포맷 형식에 맞춰서 입력해주면 된다.
XOR Properties
bytes_to_long() 함수는 바이트 값을 정수(long)형태의 값으로 변환한다.
long_to_bytes() 함수는 정수(long)형태 값을 바이트
로 변환함 이라는 원리를 알고 해야함 근데 여기서
바이트는 그냥 로마자나 뭐 이런 숫자의 최소 단위라는데 ))
여기서 중요한건 위에서 했던..
xor starter
bytes.fromhex() 함수를 사용해서
16진수 바이트로 변환 할수 있음
.hex() 는 바이트 문자열에서 호출 되어서 16진수 표현을 얻을수있다함
이라고 했던 이 개념을 떠올려야한다.
bytes.fromhex = 16진수를 바이트로 바꾸는거임
근데 문제에서 정수로 바꾸라는 힌트를 줬으니까
bytes.fromhex 로만 쓰면 바이트로만 나오는거임 정수로 나오려면
bytes_to_long(bytes.fromhex
이렇게 쓸 생각을 해야함 해석하면
16진수를 바이트 (bytes.fromhex)로 바이트를 다시 정수로 (bytes_to_long)
또 멘토링 하면서 알게된 xor성질중에
xor한 값과 xor한요소 하나를 xor하면
나머지 한 요소가 나오는거
ex))
a^b = c
c^a = b 이렇게
from Crypto.Util.number import*
key1 = bytes_to_long(bytes.fromhex("a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313"))
key2 =key1^bytes_to_long(bytes.fromhex("37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e"))
key3 =key2^bytes_to_long(bytes.fromhex( "c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1"))
flag = bytes_to_long(bytes.fromhex( "04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf"))
근데
Print 소스를 어떻게 짜야할지 모르겠을 뿐더러 소스코드에
오류가 있는거같다
from Crypto.Util.number import*
key1 = bytes_to_long(bytes.fromhex("a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313"))
key2 =key1^bytes_to_long(bytes.fromhex("37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e"))
key3 =key2^bytes_to_long(bytes.fromhex( "c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1"))
flag = bytes_to_long(bytes.fromhex( "04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf"))^key1^key2^key3
print((long_to_bytes(flag)))
그래서 생각해보니 bytes to long 쓰고 flag 값은 key1^key2^key3을 해야 나온다고 했으니까 flag 값에
xor을 해주는것을 까먹었다
print는 다시 bytes_to_long을
long_to_bytes로 바꾸어서
flag 값을
원래의 형태(bytes)로 바꾸어서 출력 해보려고 하니까
flag값이 나왔다
*crypto{x0r_i5_ass0c1at1v3}