4 ms·
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]
by olefoo 13y ago
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 '
- Mithrandir 13y agoAlso: '416D65726963612043616E20436F646520'.decode('hex') Edit: In Python 3, bytes.fromhex('416D65726963612043616E20436F646520').decode('utf-8')
- Patrick_Devine 13y agonice! Mine was similar to olefoo's: 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.
- olefoo 13y agoSweet, I didn't even think of using the string methods; always nice to have a blind spot pointed out.
- VMG 13y agoMithrandir Can Code!
- narfquat 13y agoand the ruby equivalent: "416D65726963612043616E20436F646520".scan(/../).map { |x| x.hex.chr }.join => "America Can Code "
- randomdata 13y ago['416D65726963612043616E20436F646520'].pack('H*') => "America Can Code "
- raldi 13y agoPerl: print pack "H*", "416D65726963612043616E20436F646520"
- pella 13y agohttp://www.string-functions.com/hex-string.aspx http://www.string-functions.com/hex-string.aspx
- goldenkey 13y agoIf I saw someone I hired using that website, I'd immediately fire them for incompetence. It's not even client-side, it submits a form post...
- habitue 13y agoI got a really crazy one-liner: ''.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
- pwg 13y agoTCL: % 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 '
- nitrogen 13y agoI thought it curious that it included a space at the end (0x20), before I ever decoded it. Anyway, here's my contribution to the hex-to-binary Rosetta thread. echo '416D65726963612043616E20436F646520' | xxd -p -r --> 'America Can Code '
- goldenkey 13y agoJS "416D65726963612043616E20436F646520".match(/.{2}/g).map(function(s){ return String.fromCharCode( parseInt(s,16) ); }).join("") Or the 1 liner :-) unescape("416D65726963612043616E20436F646520".replace(/(.{2})/g, "%$1"))