【XCTF 攻防世界】CRYPTO 密码学 新手练习区 easychallenge

题目链接:https://adworld.xctf.org.cn/task/answer?type=crypto&number=5&grade=0&id=5119

下载附件,得到一个pyc文件

有关pyc文件的介绍:https://www.jianshu.com/p/7a3a547952c0

那么我们反编译一下看看它的源码是什么

在线反编译:在线pyc反编译

得到以下代码:

#! /usr/bin/env python 2.7 (62211)
#coding=utf-8
# Compiled at: 2018-08-08 22:29:44
#Powered by BugScaner
#http://tools.bugscaner.com/
#如果觉得不错,请分享给你朋友使用吧!
import base64
 
def encode1(ans):
    s = ''
    for i in ans:
        x = ord(i) ^ 36
        x = x + 25
        s += chr(x)
 
    return s
 
 
def encode2(ans):
    s = ''
    for i in ans:
        x = ord(i) + 36
        x = x ^ 36
        s += chr(x)
 
    return s
 
 
def encode3(ans):
    return base64.b32encode(ans)
 
 
flag = ' '
print 'Please Input your flag:'
flag = raw_input()
final = 'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E==='
if encode3(encode2(encode1(flag))) == final:
    print 'correct'
else:
    print 'wrong'

自己写一个解密脚本:

import base64
def decode1(ans):
    s=''
    for i in ans:
        x=ord(i)-25
        x=chr(x^36)
        s+=x
    return s

def decode2(ans):
    s=''
    for i in ans:
        x=i  //在这里不用再使用ord()了,因为base32decode输出的是int
        x=x ^ 36
        x=chr(x-36)
        s+=x
    return s

def decode3(ans):
    return base64.b32decode(ans)
    
final='UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E==='
flag=decode1(decode2(decode3(final)))
print(flag)

需要注意的是
1,base32decode输出的是int
2,^按位异或,一个字符串两次按位异或即为原字符串

得到flag

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值