๐Ÿ”’ Cyber Security/Cryptography (์•”ํ˜ธํ•™)

[CryptoHack] General Challenge - XOR

์„ ๋‹ฌ 2022. 11. 10. 19:27
๋ฐ˜์‘ํ˜•

https://cryptohack.org/challenges/general/

 

CryptoHack – Home

A fun, free platform to learn about cryptography through solving challenges and cracking insecure code. Can you reach the top of the leaderboard?

cryptohack.org

 

 

     


    XOR Starter

     Given the string "label", XOR each character with the integer 13. Convert these integers back to a string and submit the flag as crypto{new_string}.

     The Python pwntools library has a convenient xor() function that can XOR together data of different types and lengths. But first, you may want to implement your own function to solve this.

     

    "label" ์ด๋ผ๋Š” ๋ฌธ์ž์—ด์„ 13์ด๋ผ๋Š” ์ •์ˆ˜ํ˜•๊ณผ xor ์—ฐ์‚ฐ์„ ํ•˜๋ฉด ๋œ๋‹ค.

    code = "label"
    
    decode = []
    for i in code :
      decode.append(ord(i) ^ 13)
    
    for d in decode:
      print(chr(d))

     


    XOR Properties

    Let's try this out in action! Below is a series of outputs where three random keys have been XOR'd together and with the flag. Use the above properties to undo the encryption in the final line to obtain the flag.

    KEY1 = a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313
    KEY2 ^ KEY1 = 37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e
    KEY2 ^ KEY3 = c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1
    FLAG ^ KEY1 ^ KEY3 ^ KEY2 = 04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf

     Before you XOR these objects, be sure to decode from hex to bytes.

     

    A^B ์—์„œ A๋ฅผ XOR ์—ฐ์‚ฐํ•ด์ฃผ๋ฉด B ๊ฐ€ ๋‚จ๋Š”๋‹ค๋Š” ์‚ฌ์‹ค์„ ์ด์šฉํ•˜์ž.

    (A^B) ^ A = B

     

    from Crypto.Util.number import *
    
    hint0 = "a6c8b6733c9b22de7bc0253266a3867df55acde8635e19c73313" # KEY1
    hint1 = "37dcb292030faa90d07eec17e3b1c6d8daf94c35d4c9191a5e1e" # KEY1 ^ KEY2
    hint2  = "c1545756687e7573db23aa1c3452a098b71a7fbf0fddddde5fc1" # KEY2 ^ KEY3
    hint3 = "04ee9855208a2cd59091d04767ae47963170d1660df7f56f5faf" # KEY1 ^ KEY2 ^ KEY3 ^ FLAG
    
    # KEY1 = hint0
    KEY1 = bytes_to_long(bytes.fromhex(hint0))
    
    # KEY2 = (KEY1 ^ KEY2) ^ KEY1
    KEY2 = bytes_to_long(bytes.fromhex(hint1)) ^ KEY1
    
    # KEY3 = (KEY2 ^ KEY3) ^ KEY2
    KEY3 = bytes_to_long(bytes.fromhex(hint2)) ^ KEY2
    
    # FLAG = (KEY1 ^ KEY2 ^ KEY3 ^ FLAG) ^ KEY1 ^ KEY2 ^ KEY3
    FLAG = bytes_to_long(bytes.fromhex(hint3)) ^ KEY1 ^ KEY2 ^ KEY3
    
    print(str(long_to_bytes(FLAG), "UTF-8"))

     

    ๋”๋ณด๊ธฐ

    crypto{x0r_i5_ass0c1at1v3}

     


    Favourite Bite

    For the next few challenges, you'll use what you've just learned to solve some more XOR puzzles.

    I've hidden some data using XOR with a single byte, but that byte is a secret. Don't forget to decode from hex first.

    73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d

     

    ๋ฐ˜์‘ํ˜•

    '๐Ÿ”’ Cyber Security > Cryptography (์•”ํ˜ธํ•™)' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    [CryptoHack] General Challenge - Ecoding  (0) 2022.11.10
    [CryptoHack] Introduction to CryptoHack  (0) 2022.11.10