0

I'm working with my own 91-numbers numerical system (unnonagesimal) in python 3.6 for RSA algorithm for my studies project. It works really fine but not with large numbers. Numbers I need it to work with are bigger than 1024 bits.

It doesn't work with some numbers, especially with those big ones.

The question is: Why doesn't it work?

Here's my code:

_unnonagesimal = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^/*?&<>()[]@%$#,;'`~|\"\\_"

def unnonagesimal_to_decimal(s):
    return sum([_unnonagesimal.find(var) * len(_unnonagesimal) ** i
                    for i, var in enumerate(reversed(s))])

def decimal_to_unnonagesimal(n):
    if n == 0:
        return 0
    else:
        s = ""
        while n != 0:
            s += _unnonagesimal[n % len(_unnonagesimal)]
            n = int(n / len(_unnonagesimal))

        return s[::-1]

Where:

unnonagesimal_to_decimal(s) converts unnonagesimal string s into a decimal number.

and

decimal_to_unnonagesimal(n) converts decimal int n into an unnonagesimal number.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

Alright, I just find out thanks to @user2357112

The problem was with int(blah / blah). Corrected to int(blah // blah). Now works fine.

This problem was becasue I switched to python 3 from python 2. For anyone who doesn't know: in python 2, 5/2 = 2 but in python 3, 5/2 = 2.5 yet 5//2 = 2

I just thought dividing integers are the same in python 2 and 3.

Working code in python 3.6.5:

_unnonagesimal = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^/*?&<>()[]@%$#,;'`~|\"\\_"


def unnonagesimal_to_decimal(s):
    return sum([_unnonagesimal.find(var) * len(_unnonagesimal) ** i for i, var in enumerate(reversed(s))])


def decimal_to_unnonagesimal(n):
    if n == 0:
        return 0
    else:
        s = ""

        while n != 0:
            s += _unnonagesimal[n % len(_unnonagesimal)]
            n = int(n // len(_unnonagesimal))

        return s[::-1]