by olefoo · 12y ago · 0 comments
s = '416D65726963612043616E20436F646520'
def decoder(s):
cl = [ s[i]+s[i+1] for i in range(0,len(s),2)]
cl = [int(c,16) for c in cl]
f = "".join([chr(c) for c in cl])
return f
decoder(s)
returns 'America Can Code ' '416D65726963612043616E20436F646520'.decode('hex')
Edit: In Python 3, bytes.fromhex('416D65726963612043616E20436F646520').decode('utf-8')x = "416d65726963612043616e20436f646520" ''.join([chr(int(y, 16)) for y in [x[l:l+2] for l in range(0, len(x), 2)]])
I do think it's funny that they (erroneously?) put the extra space on the end of the string. If you read the press release for the bill I don't think the 20 is supposed to be there.
''.join([chr(int(z1 + z2, 16)) for _, ((_1, z1), (_2, z2)) in groupby(enumerate(ciph), key=lambda (i, y): i // 2)])
edit: my goal was not to do indexing explicitly print pack "H*", "416D65726963612043616E20436F646520" "416D65726963612043616E20436F646520".scan(/../).map { |x| x.hex.chr }.join
=> "America Can Code " ['416D65726963612043616E20436F646520'].pack('H*')
=> "America Can Code " echo '416D65726963612043616E20436F646520' | xxd -p -r
--> 'America Can Code ' % puts [ binary format H* 416d65726963612043616e20436f646520 ]
America Can Code
Or if you want to see the trailing space: % puts '[ binary format H* 416d65726963612043616e20436f646520 ]'
'America Can Code ' "416D65726963612043616E20436F646520".match(/.{2}/g).map(function(s){
return String.fromCharCode(
parseInt(s,16)
);
}).join("")
Or the 1 liner :-) unescape("416D65726963612043616E20436F646520".replace(/(.{2})/g, "%$1"))