[Cryptanalysis] Shift cipher


Shift cipher라고 하길래 A to Z 26개를 가지고 하는건가 싶었는데 열어보니 byte 내에서 Shift를 하는건가보네요.

from Crypto.Util.number import *
import binascii,socket,sys

def gcd(a, b):
  if a == 0: return b
  return gcd(b%a, a)

def egcd(a, b):
  if a == 0:
    return (b, 0, 1)
  g, y, x = egcd(b%a,a)
  return (g, x - (b//a) * y, y)

def inv(a, m):
  g, x, y = egcd(a, m)
  if g != 1:
    raise Exception('No modular inverse')
  return x%m

# x**2 = a (mod m), m is prime
def quad_congruence_equation(a, m):
  assert((m+1)%4 == 0)
  return pow(a, (m+1)//4, m)
# m must satisfies pairwise relatively prime
def crt(a, m):
  n = len(m)
  ret = a[0]
  mod = m[0]
  for i in range(1,n):
    m1 = mod
    mod *= m[i]
    m2inv = inv(m[i],m1)
    m1inv = inv(m1,m[i])
    ret = (ret*m[i]*m2inv+a[i]*m1*m1inv)%mod
  return ret

# 0x6161 -> 'AA'
def i2s(x):
  return long_to_bytes(x).decode("utf-8")

############ my socket ###############
def interactive(socket):
  print("[+] interactive mode")
  while True:
    rr = socket.recv(2**16).decode()
    if not rr:
      print("[!] socket closed")
      return None
    print(rr)
    socket.send((input('> ')+'\n').encode())

def remote(ip, port):
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  print("[+] Connecting to {}:{}".format(ip,port))
  sock.connect((ip,port))
  print("[+] Done!")
  return sock

def sendline(socket, msg):
  if type(msg) == str: msg = msg.encode()
  if msg[-1] != b'\n': msg += b'\n'
  socket.send(msg)

###################################

s='4C 7C 6B 80 79 2B 2A 5E 7F 2A 7A 6F 7F 82 2A 80 6B 76 73 6E 6F 7C 2A 6B 80 6F 6D 2A 76 6F 2A 7A 6B 7D 7D 2A 63 79 76 6B 73 72 7F 14 0A'.split()
for i in range(len(s)):
  s[i] = int(s[i],16)
print(s)

for x in range(256):
  q = ''
  for c in s:
    q += chr((c+x)&0xff)
  print(x,q)

프랑스어네요;;

번역기를 쓰면 됩니다

'워게임 > root-me.org' 카테고리의 다른 글

[Cryptanalysis] File - PKZIP  (0) 2019.01.14
[Cryptanalysis] ELF64 - PID Encryption  (0) 2019.01.14
[Cryptanalysis] Pixel Madness  (0) 2019.01.14
[Cryptanalysis] Hash - SHA-2  (0) 2019.01.14
[Cryptanalysis] Message Digest 5  (0) 2019.01.14
[Cryptanalysis] Encoding - UU  (0) 2019.01.14
  Comments