Featured Content Slider

Home » » picoctf 2013 Trivial: 45

picoctf 2013 Trivial: 45

Vo Uu | 21:18 | 0 nhận xét
An unlocked terminal is displaying the following:
Encryption complete, ENC(???,T0pS3cre7key) = Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut ab8bv_w4ue0_ab8v_DDU
You poke around and find this interesting file.

Từ đoạn encrypt đã cho:


#!/usr/bin/env python
import sys

alphaL = "abcdefghijklnmopqrstuvqxyz"
alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"
num    = "0123456789"
keychars = num+alphaL+alphaU

if len(sys.argv) != 3:
  print "Usage: %s SECRET_KEY PLAINTEXT"%(sys.argv[0])
  sys.exit()

key = sys.argv[1]
if not key.isalnum():
  print "Your key is invalid, it may only be alphanumeric characters"
  sys.exit()

plaintext = sys.argv[2]

ciphertext = ""
for i in range(len(plaintext)):
  rotate_amount = keychars.index(key[i%len(key)])
  if plaintext[i] in alphaL:
    enc_char = ord('a') + (ord(plaintext[i])-ord('a')+rotate_amount)%26
  elif plaintext[i] in alphaU:
    enc_char = ord('A') + (ord(plaintext[i])-ord('A')+rotate_amount)%26
  elif plaintext[i] in num:
    enc_char = ord('0') + (ord(plaintext[i])-ord('0')+rotate_amount)%10
  else:
    enc_char = ord(plaintext[i])
  ciphertext = ciphertext + chr(enc_char)

print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,ciphertext)


Ta sửa lại 1 xíu là được, cho key và plaintext vào luôn 

#!/usr/bin/env python
import sys
alphaL = "abcdefghijklnmopqrstuvqxyz"
alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"
num    = "0123456789"
keychars = num+alphaL+alphaU
key = "T0pS3cre7key"
plaintext = "Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut ab8bv_w4ue0_ab8v_DDU"
ciphertext = ""
for i in range(len(plaintext)):
  rotate_amount = keychars.index(key[i%len(key)])
  if plaintext[i] in alphaL:
    enc_char = ord('a') + (ord(plaintext[i])-ord('a')-rotate_amount)%26
  elif plaintext[i] in alphaU:
    enc_char = ord('A') + (ord(plaintext[i])-ord('A')-rotate_amount)%26
  elif plaintext[i] in num:
    enc_char = ord('0') + (ord(plaintext[i])-ord('0')-rotate_amount)%10
  else:
    enc_char = ord(plaintext[i])
  ciphertext = ciphertext + chr(enc_char)
print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,ciphertext)
user_submitted = raw_input("Wait")

C:\Users\WIN7>C:\Python27\python.exe "E:\CTF\picoctf 2013\encrypt2.py"
Encryption complete, ENC(Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut
 ab8bv_w4ue0_ab8v_DDU,T0pS3cre7key) = You hawe successfully decrypwed the messag
e! The key is th4ts_w0rs3_th4n_DES

Key là: th4ts_w0rs3_th4n_DES
Share this article :

0 nhận xét:

Đăng nhận xét

Recent Post

Test Footer 1

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. The UG - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger