Author Topic: Python decimal to hexadecimal converter line?  (Read 1758 times)

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Python decimal to hexadecimal converter line?
« on: December 17, 2011, 09:29:53 pm »
I looked on the web and I couldn't find a working one. So anyone have an idea? Or one in cocoa if possible.
䅁㈥퀞
퀞㈥ꆱ

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #1 on: December 17, 2011, 09:57:40 pm »
Code: (Python) [Select]

#convert string to hex
def toHex(s):
    lst = []
    for ch in s:
        hv = hex(ord(ch)).replace('0x', '')
        if len(hv) == 1:
            hv = '0'+hv
        lst.append(hv)
   
    return reduce(lambda x,y:x+y, lst)

#convert hex repr to string
def toStr(s):
    return s and chr(atoi(s[:2], base=16)) + toStr(s[2:]) or ''

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Re: Python decimal to hexadecimal converter line?
« Reply #2 on: December 17, 2011, 10:04:31 pm »
line 13: syntax error near unexpected token `('
This is in C so is there a way to import python?
䅁㈥퀞
퀞㈥ꆱ

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #3 on: December 17, 2011, 10:19:57 pm »
>_> You dont know python || C do you...?

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Re: Python decimal to hexadecimal converter line?
« Reply #4 on: December 17, 2011, 10:39:59 pm »
Everyone has to start sometime.
䅁㈥퀞
퀞㈥ꆱ

Don't like seeing ads? Click here to register!

Apetrick

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3513
  • Reputation: 90
  • <Apetrick> lank is 1337
  • Badges:
  • iDevices: Ipod Touch 4g
Re: Python decimal to hexadecimal converter line?
« Reply #5 on: December 17, 2011, 10:41:08 pm »
Yep i still needa start ive been puttin it aside
<%a12danrulz> Idk, but doing a DoS from an apple device is like fighting a bear with a plastic spork

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #6 on: December 17, 2011, 10:41:52 pm »
That doesnt change the fact that its python. Why do you need this?

Apetrick

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3513
  • Reputation: 90
  • <Apetrick> lank is 1337
  • Badges:
  • iDevices: Ipod Touch 4g
Re: Python decimal to hexadecimal converter line?
« Reply #7 on: December 17, 2011, 10:42:57 pm »
Probly for his memory dump or sumtin
<%a12danrulz> Idk, but doing a DoS from an apple device is like fighting a bear with a plastic spork

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Re: Python decimal to hexadecimal converter line?
« Reply #8 on: December 17, 2011, 10:44:18 pm »
Yes I need to change the crypt size from dec to hex.
䅁㈥퀞
퀞㈥ꆱ

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #9 on: December 17, 2011, 10:45:07 pm »
You shouldnt tell someone that something is a different thing when you dont know what either is. That is clearly not C, and my time spent programming C totals to about 10 minutes.

Don't like seeing ads? Click here to register!

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #10 on: December 17, 2011, 10:48:41 pm »
And it works fine for me so you typed it in wrong.

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Re: Python decimal to hexadecimal converter line?
« Reply #11 on: December 17, 2011, 10:54:41 pm »
Let me try something then I will retry yours.
䅁㈥퀞
퀞㈥ꆱ

Apetrick

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3513
  • Reputation: 90
  • <Apetrick> lank is 1337
  • Badges:
  • iDevices: Ipod Touch 4g
Re: Python decimal to hexadecimal converter line?
« Reply #12 on: December 17, 2011, 10:57:00 pm »
What are you gunna try cuz it might make a good tut changing that
<%a12danrulz> Idk, but doing a DoS from an apple device is like fighting a bear with a plastic spork

Dnawrkshp

  • Jr. Members
  • **
  • Posts: 56
  • Reputation: 3
  • Computers: Mac Mini running OS 10.5, Mac Desktop running OS 10.3
  • iDevices: iPod Touch 4g running OS 5.0.1 (Jailbroken-tethered)
Re: Python decimal to hexadecimal converter line?
« Reply #13 on: December 17, 2011, 11:32:52 pm »
Ok found an answer,
#!/bin/bash
# hexconvert.sh: Convert a decimal number to hexadecimal.

E_NOARGS=85 # Command-line arg missing.
BASE=16     # Hexadecimal.

if [ -z "$1" ]
then        # Need a command-line argument.
  echo "Usage: $0 number"
  exit $E_NOARGS
fi          # Exercise: add argument validity checking.


hexcvt ()
{
if [ -z "$1" ]
then
  echo 0
  return    # "Return" 0 if no arg passed to function.
fi

echo ""$1" "$BASE" o p" | dc
#                  o    sets radix (numerical base) of output.
#                    p  prints the top of stack.
# For other options: 'man dc' ...
return
}

hexcvt "$1"

exit

䅁㈥퀞
퀞㈥ꆱ

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 216
  • Badges:
Re: Python decimal to hexadecimal converter line?
« Reply #14 on: December 17, 2011, 11:33:54 pm »
Thats bash, not python