Friday, 15 April 2011

encryption - Methods all need to be indented one level in to indicate that they are methods of the class in python -



encryption - Methods all need to be indented one level in to indicate that they are methods of the class in python -

i'm next rsa algorithm wiki: http://en.wikipedia.org/wiki/rsa_(algorithm)

i using python 3.3.0 , i'm trying rsa encryption , ran 2 problems don't know how do.

in encryptions class, methods need indented 1 level in indicate methods of class , not global functions.

when main script asks input @ end, if nail return, exception thrown python reached unexpected eof.

how can ?

my code far:

modular.py

def _base_b_convert(n, b): if b < 1 or n < 0: raise valueerror("invalid argument") q = n = [] while q != 0: value = int(q % b) a.append(value) q =int(q / b) homecoming def mod_exp(base, n, mod): if base of operations < 0 or n < 0 or mod < 0: raise valueerror("invalid argument") = (_base_b_convert(n, 2)) x = 1 pow = base of operations % mod in range(0, len(a)): if a[i] == 1: x = (x * pow) % mod pow = pow**2 % mod homecoming x

main.py

from encryptions import encryptions def main(): enc = encryptions() message = enc.encrypt(message) print(message) print() print("decrypting message:") message = enc.decrypt(message) print(message) input("--press key end--") if __name__ == '__main__': main()

input() in python 2 not think -- rather, evaluates string inputted python code, not want. instead, utilize raw_input.

as indentation problem, that's python syntax. nil can do.

python encryption rsa

No comments:

Post a Comment