zoukankan      html  css  js  c++  java
  • bugku 之 crypto:进制转换的python脚本

    题目如下:

     text.txt的内容:

     

    知识点:python怎么做进制转换

    除了自己按照计算方法写一遍进制转换,可以用python自带的强制转换:

    int(a,num)

    其中,int是转换成十进制整数类型,a是待转换数字,num是a的进制,默认是10进制,在本题中可以写2,8,16

    然后用格式化输出:

    print("%c"%a,end="")

    按照ASCII将整数转化成字母,end表示结尾符,这里为空字符串

    所以代码如下:

    a="d87 x65 x6c x63 o157 d109 o145 b100000 d116 b1101111 o40 x6b b1100101 b1101100 o141 d105 x62 d101 b1101001 d46 o40 d71 x69 d118 x65 x20 b1111001 o157 b1110101 d32 o141 d32 d102 o154 x61 x67 b100000 o141 d115 b100000 b1100001 d32 x67 o151 x66 d116 b101110 b100000 d32 d102 d108 d97 o147 d123 x31 b1100101 b110100 d98 d102 b111000 d49 b1100001 d54 b110011 x39 o64 o144 o145 d53 x61 b1100010 b1100011 o60 d48 o65 b1100001 x63 b110110 d101 o63 b111001 d97 d51 o70 d55 b1100010 d125 x20 b101110 x20 b1001000 d97 d118 o145 x20 d97 o40 d103 d111 d111 x64 d32 o164 b1101001 x6d o145 x7e"

    b=[]
    b=a.split(' ')

    for i in b:
    if i[0]=='d':
    temp=int(i[1:])
    print("%c"%temp,end="")

    if i[0]=='o':
    temp=int(i[1:],8)
    print("%c"%temp,end="")
    if i[0]=='x':
    temp=int(i[1:],16)
    print("%c"%temp,end="")
    if i[0]=='b':
    temp=int(i[1:],2)
    print("%c"%temp,end="")

    运行结果如下:

    Welcome to kelaibei. Give you a flag as a gift.  flag{1e4bf81a6394de5abc005ac6e39a387b} . Have a good time~

     

     顺手写了一个实现题目加密方式的python:

    import random
    string=input()
    oldstr=string
    newstr=""
    for i in oldstr:
    temp=random.randint(1,4)
    if temp==1:
    newstr+="b"
    newstr+="{:b}".format((ord(i)))
    if temp==2:
    newstr+="d"
    newstr+="{:d}".format((ord(i)))
    if temp==3:
    newstr+="o"
    newstr+="{:o}".format((ord(i)))
    if temp==4:
    newstr+="x"
    newstr+="{:x}".format((ord(i)))
    newstr+=" "
    print(newstr)

  • 相关阅读:
    Django中的分页操作、form校验工具
    Django之form表单操作
    手写版本orm
    mysql注入问题
    MySQL基本操作
    初识数据库
    进程池、线程池
    信号量
    event事件
    死锁
  • 原文地址:https://www.cnblogs.com/yunqian2017/p/12325963.html
Copyright © 2011-2022 走看看