Skip to content

Instantly share code, notes, and snippets.

@vngkv123
Created September 4, 2017 15:39
Show Gist options
  • Save vngkv123/25d2c73d933b174aba4d01b46fe5ef13 to your computer and use it in GitHub Desktop.
Save vngkv123/25d2c73d933b174aba4d01b46fe5ef13 to your computer and use it in GitHub Desktop.
MMA CTF 2017 3rd my_simple_cipher
import sys
import random
from pwn import *
from binascii import *
key = ["E", "N", "J", "0", "Y", "H"]
flag = ["T", "W", "C", "T", "F", "{"]
enc = unhexlify("7c153a474b6a2d3f7d3f7328703e6c2d243a083e2e773c45547748667c1511333f4f745e")
msg = "A" * 21 + "|" + "B" * 13
for i in xrange(7):
key.append(None)
# msg len -> 35
# enc len -> 36 1 + 21 + 1 + 13
# encrypted += chr((ord(message[i]) + ord(key[i % len(key)]) + ord(encrypted[i])) % 128)
for i in xrange(4):
index = 22 + i
key_idx = 9 + i
for j in xrange(128):
if ord(enc[index + 1]) == (ord(key[i]) + j + ord(enc[index])) % 128:
key[key_idx] = chr(j)
for i in xrange(3):
index = 28 + i
key_idx = 6 + i
for j in xrange(128):
if ord(enc[index + 1]) == (ord(key[2 + i]) + j + ord(enc[index])) % 128:
key[key_idx] = chr(j)
log.info("Find Key : " + "".join(key))
reskey = "".join(key)
resflag = ''
for i in xrange(21):
for j in xrange(128):
if ord(enc[i + 1]) == (ord(key[i % 13]) + j + ord(enc[i])) % 128:
resflag += chr(j)
log.info("Flag : " + resflag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment