Search code examples
pythonoctal

How to convert string "0671" or "0x45" into integer form with 0 and 0x in the beginning


I wanted to make my own encryption algorithm and decryption algorithm , encryption algorithm works fine and converts ascii value of the characters into alternate hexadecimal and octal representations. But when I tried decryption, problem occured as it return int('0671') = 671, as 0671 is string type in the following code. Is there a method to convert "ox56" into integer form??????

NOTE: Following string is alternate octal and hexa of ascii value of char.

///////////////DECRYPTION///////

l="01630x7401620x6901560x67"
f=len(l)
k=0
d=0
x=[]

for i in range(0,f,4):
  g=l[i:i+4]
  print g 
  k=k+1   
  if(k%2==0):
  p=g
  print p
  else:
  p=int(g)
  print p

Solution

  • there you go (s is the string)

    int(s,0)