首页
社区
课程
招聘
[求助]关于ASCIIHexDecode解密算法
发表于: 2010-9-10 10:16 7358

[求助]关于ASCIIHexDecode解密算法

2010-9-10 10:16
7358
ASCIIHexDecode的解密算法大致如下:
      针对每一对16进制的数据,产生一个字节的二进制数据。所有的空白字符将被忽略。字符“>”表示结束。任何其他字符会导致错误。代码(python)如下:

hex_re = re.compile(r'([a-f\d]{2})', re.IGNORECASE)
trail_re = re.compile(r'^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$', re.IGNORECASE)
def asciihexdecode(data):
    """
    ASCIIHexDecode filter: PDFReference v1.4 section 3.3.1
    For each pair of ASCII hexadecimal digits (0-9 and A-F or a-f), the
    ASCIIHexDecode filter produces one byte of binary data. All white-space
    characters are ignored. A right angle bracket character (>) indicates
    EOD. Any other characters will cause an error. If the filter encounters
    the EOD marker after reading an odd number of hexadecimal digits, it
    will behave as if a 0 followed the last digit.
    
    >>> asciihexdecode('61 62 2e6364   65')
    'ab.cde'
    >>> asciihexdecode('61 62 2e6364   657>')
    'ab.cdep'
    >>> asciihexdecode('7>')
    'p'
    """
    decode = (lambda hx: chr(int(hx, 16)))
    out = map(decode, hex_re.findall(data))
    m = trail_re.search(data)
    if m:
        out.append(decode("%c0" % m.group(1)))
    return ''.join(out)


      现在需要写一个加密算法,但是不清楚什么时候加上空格,加几个空格?希望清楚此算法的大侠给予帮助。

拜谢!

附录:
      解密实例: input :"65 47  79  41  4c   7a  56 45 4c  76 6e>"
                      output: "eGyALzV"

现在不知道怎么处理相反的过程,也就是加密过程

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 998
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
你是想生成数据然后测试吧。空格加几个或者加不加都无所谓。因为解密的时候是忽略空格的。所以对于加密,你可以采用随机生成空格的方法。
2010-9-10 12:20
0
雪    币: 9
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
呃,我发现不是无所谓的。觉得ASCIIHexDecode算法不可能是这个无所谓的加几个空格。继续等待!

还是多谢您!
2010-9-10 14:24
0
雪    币: 9
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
找到加密算法了,原来空格是靠rand()函数来随机确定个数的。代码(ruby)如下:
[LIST=1]
[*]def ASCIIHexWhitespaceEncode(str)
[*]		result = ""
[*]		whitespace = ""
[*]		str.each_byte do |b|
[*]			result << whitespace << "%02x" % b
[*]			whitespace = " " * (rand(3) + 1)
[*]		end
[*]		result << ">"
[*]	end
[/LIST]
2010-9-10 14:35
0
雪    币: 998
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
那不还是跟我说的一样么,呵呵。
2010-9-11 23:18
0
游客
登录 | 注册 方可回帖
返回
//