So far I have built around half of the app and things appear to be working out thanks to Yoriz.

The part of the app that I am attempting at this point is the base conversions. I know conversion isn't the proper term as I am just displaying the same information in different bases.

I've written this little test script that I have been playing around with, and I think it is accurate, but I'm not really sure. Some of the Base64 converters that I have used give me different info than what I get from my tests, so I am a little concerned. But all the other base conversions appear to be working...I think.

- Code: Select all
`base_names = {`

2:"Binary"

, 3:"Ternary"

, 4:"Quaternary"

, 5:"Quinary"

, 6:"Senary"

, 7:"Septenary"

, 8:"Octal"

, 9:"Nonary"

, 10:"Decimal"

, 11:"Undenary"

, 12:"Duodecimal"

, 16:"Hexadecimal"

, 17:"Septendecimal"

, 19:"Decennoval"

, 20:"Vigesimal"

, 30:"Trigesimal"

, 32:"Duotrigesimal"

, 40:"Quadragesimal"

, 50:"Quinquagesimal"

, 60:"Sexagesimal"

, 64:"Base 64"

}

for key, value in base_names.iteritems():

num_test = 96

basenum = key

array = []

while num_test != 0:

base_remainder = num_test % basenum

#If statements to determine proper plac in chr table (11 != a)

if base_remainder < 10:

array.append(chr(48 + base_remainder))

elif base_remainder < 36:

array.append(chr(55 + base_remainder))

elif base_remainder < 133:

array.append(chr(61 + base_remainder))

num_test = num_test // basenum

print value, ''.join([str(var) for var in array])[::-1]

base_num = 64

test_val = "1W"

test_len = 0

array2 = []

for val in test_val[::-1]:

if ord(val) > 96:

array2.append((ord(val) - 61) * (base_num ** test_len))

elif ord(val) > 64:

array2.append((ord(val) - 55) * (base_num ** test_len))

elif ord(val) > 47:

array2.append((ord(val) - 48) * (base_num ** test_len))

test_len = test_len + 1

print sum(array2)

I will turn this into a class, and make some variable name changes to it. I will also add on the prefixes and suffixes so that 0o is octal and 0b is binary and == is Base64 and so on. I just wanted to get something working.

I decided against using binascii as it would only be able to do binary, octal, decimal, and hexadecimal, and I definitely wanted to have duotrigesimal and base 64. Also rather than using two different pieces of code to do the same conversions I decided to just write one small math script to do all the conversions. This gives me the capability to do any base conversions (13, 43, etc..) if I so choose.

My questions would be, is this script accurate? Is the a better way to do this? (like a function that I don't know about)