Code Duplication    Length = 17-19 lines in 2 locations

server/lib/rsa/_version200.py 1 location

@@ 66-84 (lines=19) @@
63
64
    return integer
65
66
def int2bytes(number):
67
    """Converts a number to a string of bytes
68
69
    >>>int2bytes(123456789)
70
    '\x07[\xcd\x15'
71
    >>> bytes2int(int2bytes(123456789))
72
    123456789
73
    """
74
75
    if not (type(number) is types.LongType or type(number) is types.IntType):
76
        raise TypeError("You must pass a long or an int")
77
78
    string = ""
79
80
    while number > 0:
81
        string = "%s%s" % (chr(number & 0xFF), string)
82
        number /= 256
83
84
    return string
85
86
def to64(number):
87
    """Converts a number in the range of 0 to 63 into base 64 digit

server/lib/rsa/_version133.py 1 location

@@ 68-84 (lines=17) @@
65
66
    return integer
67
68
def int2bytes(number):
69
    """Converts a number to a string of bytes
70
71
    >>> bytes2int(int2bytes(123456789))
72
    123456789
73
    """
74
75
    if not (type(number) is types.LongType or type(number) is types.IntType):
76
        raise TypeError("You must pass a long or an int")
77
78
    string = ""
79
80
    while number > 0:
81
        string = "%s%s" % (chr(number & 0xFF), string)
82
        number /= 256
83
84
    return string
85
86
def fast_exponentiation(a, p, n):
87
    """Calculates r = a^p mod n