You are not logged in.

#1 2007-02-14 17:01:27

noriko
Member
From: In My Mind
Registered: 2006-06-09
Posts: 535
Website

Hex | str2hex and hex2str

the other day one of my clan-members started talking in leetspeak ..
and called me a noob so, i decided to show him;
told him real men speak in hex; not leet/hex -speak
but of course i can't remember the ascii codes .. so i wrote these two scripts to do the conversion..

#!/usr/bin/env python
#/*/
 #* hex2str.py
 #* Copyright Shane Lane
 #* norrian@gmail.com
 #* this code is released under GNU GPL (General Public License)
 #*
#/*/ 
import sys, signal
from string import replace
_head = "hex2str.py | converts a hex2str.py string back to text\npress Ctrl+C to exit.\n"
print _head , ' - '*(len(_head)/4)

#signal handle is just cosmetik? to prevent the ugly error
#if you kill the script with ctrl+c
def signal_handler(signal, frame):
    print "\n"
    sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)


def hex2str(st):
    out = ''
    while len(st) > 0:
        out += chr(int(st[0:2], 16))
        st = st[2:]
    return out
    
while True:
    _in = raw_input('hex2str:> ')
    if len(_in) > 0:
        print '         ',hex2str(_in).replace('x',' ').upper()
#!/usr/bin/env python
#!/usr/bin/env python
#/*/
 #* hex2str.py
 #* Copyright Shane Lane
 #* norrian@gmail.com
 #* this code is released under GNU GPL (General Public License)
 #*
#/*/ 
import sys, signal
from string import replace
_head = "str2hex.py | converts a string of characters to hex\npress Ctrl+C to exit.\n"
print _head , ' - '*(len(_head)/4)


def signal_handler(signal, frame):
    print "\n"
    sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)


def str2hex(word):
    out = ''
    for char in word:
        out += hex(ord(char))
    return out
    
while True:
    _in = raw_input('str2hex:> ')
    if len(_in) > 0:
        _in = str2hex(_in).replace('0x','').upper()
        print '         ',_in

The.Revolution.Is.Coming - - To fight, To hunger, To Resist!

Offline

Board footer

Powered by FluxBB