Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 198
Image: ubuntu2004

ITERATED ENCRYPTION

def ASCIIPad(Message): K = (map(ord,reversed(Message))); le= len(K); x = [100+K[i] for i in range(le)]; x = ZZ(x,1000); return(x); ################################################################################################# # The input is a number and the output is the original message. If the input is not padded ASCII# # version of a message it returns the value: "This is not a padded ASCII string" # ################################################################################################# def ASCIIDepad(Number): n = Number.ndigits() % 3; if (n > 0): print("This is not a padded ASCII string\n"); else: L = [((Number - (Number % (1000^i)))/1000^i)%1000 - 100 for i in range(Number.ndigits()/3)]; N = ""; for i in range(Number.ndigits()/3): N = chr(L[i]) + N; return(N) def isASCIIPadded(Number): N = "" n = Number.ndigits() % 3; if (n > 0): return False; L = [((Number - (Number % (1000^i)))/1000^i)%1000 - 100 for i in range(Number.ndigits()/3)]; for i in range(Number.ndigits()/3): if L[i] < 0: return False if L[i] > 255: return False return True

Example. Let (R,e) be an RSA public key and E be the ciphertext encrypted using the given RSA key. Decrypt the message!

R=315562173921131111550753275258954314886929684614433857059068225329589007516900986203500713113234143069878550293 e=1835588100642725811278316299646156385857628660058608776628872255463681001129596115865795858135978837517124882698892069345209251312769967638417909171551219459094621692202465346003400944724101186482909006146466321559204641 E=150598315159426420417362370315760759643687452249127260593893330249875774660837569082216166241764228321707042114 found = False while(not found): E = power_mod(E,e,R) if(isASCIIPadded(E)): found = True print "The message is:", ASCIIDepad(E)
The message is: Elliptic Curve Cryptography

The function IteratedEncryption takes a ciphertext along with an RSA key and encrypts until an ASCII padded message is found.

def IteratedEncryption(Ciphertext,EncExp,Modulus): found = False E = Ciphertext while(not found): power_mod(E,EncExp,Modulus) if(isASCIIPadded(E)): found = True print "Padded Message is:", E print "Message is:", ASCIIDepad(E) return E; IteratedEncryption(E,e,R)
Padded Message is: 169208208205212216205199132167217214218201132167214221212216211203214197212204221 Message is: Elliptic Curve Cryptography 169208208205212216205199132167217214218201132167214221212216211203214197212204221