#!/usr/bin/python sig=""" -----BEGIN PGP SIGNED MESSAGE----- # # Pure Crypto Program based on modular exponentiation and RSA alone. # # 1/9/2003 (version 0.A) (c) 2003 Ralf Senderek # # This is free software. # The code was written by Ralf Senderek. # Use this software on your own risk or not at all. # There is NO warranty; not even for MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. """ import pure import sys import time import os # OS-specific stuff EOL = "\n" Console = "/dev/tty" if os.name == "nt" or os.name == "dos" : Console = "CON" #################################################################### # Functions # #################################################################### def prompt_Console(P): print P Flags = 0 Mode = 0 try: CONSOLE = os.open(Console, Flags, Mode) PASS = "" CHAR = os.read(CONSOLE, 1) while CHAR != EOL : PASS = PASS + CHAR CHAR = os.read(CONSOLE, 1) except: print "Cannot open console for reading." sys.exit(4) return PASS #################################################################### def ENCRYPTION() : Plaintext = "" for Line in Text : Plaintext = Plaintext + Line # select cryptosystem UserInformation = "l" Prompt = EOL + "To select the recipient's public key please enter recipient's user ID :"+EOL+ " shows a list."+EOL while UserInformation == "l" or UserInformation == "L": UserInformation = prompt_Console(Prompt) if UserInformation == "l" or UserInformation == "L": pure.print_keylist() Result = pure.select_cryptosystem(UserInformation) if Result : print "Using public key for " , pure.UserID, EOL Crypt = pure.encrypt(Plaintext, pure.Encryption, pure.Modulus) Ciphertext = "" for Number in Crypt : Ciphertext = Ciphertext + str(Number) + EOL if sys.argv[2] == "-pipe" : OUTFILE.write(Ciphertext) OUTFILE.close() else: try: FILE = open(sys.argv[2]+".pcp" , "w") FILE.write(Ciphertext) FILE.close() print "Cryptogram written to file "+ sys.argv[2]+".pcp" + EOL except: print "Error: Cannot write file ", sys.argv[2]+".pcp" + EOL sys.exit(2) else: print EOL + "Encryption error: No public key found for " + UserInformation + EOL #################################################################### def DECRYPTION() : pure.read_cryptosystem("encryptionkey") print "Encryption key is used." pure.print_securityhash() Cryptogram = [] Errors = 0 for Line in Text : try: Number = long(Line) Cryptogram.append(Number) except: Errors = Errors + 1 if Errors : print Errors, " lines of your ciphertext are not PCP encrypted." if Errors == len(Text) : print "This is not a PCP encrypted file" sys.exit(3) pure.load_secretkey() Plain = pure.decrypt(Cryptogram, pure.Decryption, pure.Modulus) pure.burn_secretkey() if sys.argv[2] == "-pipe" : OUTFILE.write(Plain) OUTFILE.close() else: try : FILE = open(sys.argv[2]+".clear", "w") FILE.write(Plain) FILE.close() print "Plaintext written to file "+ sys.argv[2]+".clear" + EOL if pure.OS == "unix": os.system("chmod 600 " + sys.argv[2] + ".clear") except: print "Error: Cannot write plaintext file." sys.exit(2) #################################################################### def SIGNING(SigType) : print EOL + "Signing ..." + EOL # check if Signstring contains crypto Crypto = 0 for Line in Text : try: N = long(Line) Crypto = Crypto + 1 except: pass if Crypto : print EOL + "WARNING Your message contains encrypted material. WARNING" print "This is dangerous! Always sign before encrypting." print "But anyway, if you wish to continue." + EOL Signstring = "" for Line in Text: Signstring = Signstring + Line pure.read_cryptosystem("signingkey") Fingerprint = pure.hash(Signstring) Timestamp = time.ctime(time.time()) print "hash = " , pure.toString(Fingerprint) print "time = " , Timestamp print "UID = " , pure.UserID Infostring = Timestamp + " by " + pure.UserID Info = 0L for Character in Infostring : Info = Info * 256 + ord(Character) if pure.Mode == "CONSERVATIVE" : Exp = 256L else: Exp = pure.HashModulusLength SignatureNumber = 0L SignatureNumber = Info * pow(2L,Exp) + Fingerprint if SignatureNumber * 256 >= pure.Modulus : print "WARNING: The Signature-Information is too long!" print "No Signature created." InfoBits = pure.countbits(Info) print "The Signature-Information is ", InfoBits , " bits long." print "Use a longer signing key or reduce the User-Identification." sys.exit(4) # calculate Signature pure.load_secretkey() Signature = 0L Signature = pure.ModExp(SignatureNumber, pure.Decryption, pure.Modulus) pure.burn_secretkey() # check if signature verifies with the signer's public key Challenge = 0L Challenge = pure.ModExp(Signature, pure.Encryption, pure.Modulus) if Challenge != SignatureNumber : print "Error: No signature created."+EOL sys.exit(4) SignatureText = "" if SigType == "clear": SignatureText = SignatureText + "-----BEGIN PURE-CRYPTO SIGNED MESSAGE-----"+EOL SignatureText = SignatureText + Signstring + EOL SignatureText = SignatureText + "-----BEGIN PURE-CRYPTO SIGNATURE-----"+EOL SignatureText = SignatureText + pure.Hashtype + pure.Comment + EOL + EOL SignatureText = SignatureText + pure.UserID + EOL SignatureText = SignatureText + pure.toString(Signature) + EOL SignatureText = SignatureText + "-----END PURE-CRYPTO SIGNATURE-----" + EOL if sys.argv[2] == "-pipe": OUTFILE.write(SignatureText) OUTFILE.close() else: try: FILE = open(sys.argv[2]+".sig", "w") FILE.write(SignatureText) FILE.close() print EOL + "Signature written to file ", sys.argv[2] + ".sig" + EOL except: print "Error: Cannot write file ", sys.argv[2]+".sig" + EOL sys.exit(2) #################################################################### def VERIFICATION() : print EOL + "Verifying signature on file " + sys.argv[2] MessageText = [] preface = "" EncryptedSignature = 0L epilogue = "" index = 0 while index < len(Text) and \ (Text[index] != "-----BEGIN PURE-CRYPTO SIGNED MESSAGE-----"+EOL and \ Text[index] != "-----BEGIN PURE-CRYPTO SIGNATURE-----"+EOL) : preface = preface + Text[index] index = index + 1 if index == len(Text) : print "File has no signature!"+EOL sys.exit(4) if Text[index] == "-----BEGIN PURE-CRYPTO SIGNATURE-----"+EOL : # signed text is separate if sys.argv[2][-4:] == ".sig" : Filename = sys.argv[2][:-4] try: INFILE = open(Filename, "r") except: print "Cannot open file ", Filename sys.exit(4) if sys.argv[2] == "-pipe": print "Separate signatues don\'t work with pipes." sys.exit(2) try: INFILE = open(Filename, "r") except: print "Cannot open file ", Filename sys.exit(4) print "Data is assumed to be separate in file ", Filename MessageText = INFILE.readlines() NewText = [] for Line in MessageText: if Line[-2:] == "\r\n" : Line = Line[:-2] + EOL NewText.append(Line) MessageText = NewText MessageText.append(EOL) else: # read message index = index + 1 while index < len(Text) and Text[index] != "-----BEGIN PURE-CRYPTO SIGNATURE-----"+EOL : MessageText.append(Text[index]) index = index + 1 # test if file may contain a signature if index >= len(Text) : print "File has no signature!"+EOL sys.exit(4) try : index = index + 1 Hashtype = Text[index][6:10] index = index + 2 UserInformation = pure.Line(Text[index]) index = index + 1 EncryptedSignature = pure.toLong(Text[index]) index = index + 1 if Text[index] != "-----END PURE-CRYPTO SIGNATURE-----"+EOL : print "Warning: No complete signature-block found" except : print "Signature is corrupted !" sys.exit(3) while index < len(Text) and Text[index] != "-----END PURE-CRYPTO SIGNATURE-----"+EOL : index = index + 1 index = index + 1 while index < len(Text) : epilogue = epilogue + Text[index] index = index + 1 TestMessage = "" TestSignature = 0L for Line in MessageText : TestMessage = TestMessage + Line # remove single EOL from Testmessage TestMessage = TestMessage[:-1] print "Read " ,len(TestMessage), " bytes of text." PlainHash = 0L Info = 0L Infostring = "" SignatureNumber = 0L # select cryptosystem Result = pure.select_cryptosystem(UserInformation) if Result : print EOL + "Using public key for " , pure.UserID if Hashtype == "SDLH" : print EOL + "The Discrete Logarithm Hash Function was used to create this signature." pure.Mode = "PURE" elif Hashtype == "SHA1" : print EOL + "SHA1 was used to create this signature." pure.Mode = "CONSERVATIVE" pure.print_security_notice() TestHash = pure.hash(TestMessage) SignatureNumber = pure.ModExp(EncryptedSignature, pure.Encryption, pure.Modulus) if pure.Mode == "CONSERVATIVE" : PlainHash = SignatureNumber % pow(2L,256L) Info = SignatureNumber / pow(2L,256L) else: PlainHash = SignatureNumber % pow(2L,pure.HashModulusLength) Info = SignatureNumber / pow(2L,pure.HashModulusLength) Infostring = pure.LongListToString([Info]) if PlainHash == TestHash : print EOL+"GOOD SIGNATURE made ", Infostring , EOL+EOL sys.exit(0) else : print EOL+"***BAD SIGNATURE*** in file " + sys.argv[2] + EOL+EOL sys.exit(2) else: print EOL + "The public key used to verify this signature is unavailable." print UserInformation + EOL ######################################################################### # Main # ######################################################################### pure.print_banner() if len(sys.argv) > 1 and sys.argv[1] == "-wipe" : # wiping files try: File = open(pure.Home + "wipedata", "r") Entropy = File.read() print len(Entropy), " Bytes wipedata available." File.close() except: print EOL + "Your wipedata file is unavailable !" + EOL sys.exit(4) for filename in sys.argv[2:] : print "wiping " + filename try: Target = open(filename, "r") Text = Target.read() L = len(Text) Target.close() Target = open(filename, "w") while L > len(Entropy) : L = L - len(Entropy) Target.write(Entropy) # now L <= Len(Entropy) Target.write(Entropy[:L]) Target.close() print "File " + filename + " filled up with random data" if pure.OS == "unix": os.system("rm -f " + filename) if pure.OS == "billware": os.system("del " + filename) print "and deleted from the filesystem" + EOL except: print "Nothing done." + EOL sys.exit(0) # command line overwrites default values if len(sys.argv) == 4 and sys.argv[1] == "-pure" : del sys.argv[1] pure.Mode = "PURE" pure.Hashtype = "Hash: SDLH " if pure.Comment == pure.SHA_Comment : pure.Comment = pure.Pure_Comment if len(sys.argv) == 3 : if sys.argv[2] == "-pipe" : INFILE = sys.stdin # pipe input OUTFILE = sys.stdout # pipe output sys.stdout = sys.stderr # print commands else: try: INFILE = open(sys.argv[2], "r") except: print "File " + sys.argv[2] + " is not accessible."+EOL sys.exit(4) Text = INFILE.readlines() NewText = [] for Line in Text: if Line[-2:] == "\r\n" : Line = Line[:-2] + EOL NewText.append(Line) Text = NewText INFILE.close() pure.print_security_notice() if sys.argv[1] != "-d" : print "Checking the signing key\'s integrity." pure.read_cryptosystem("signingkey") pure.print_securityhash() if sys.argv[1] == "-e" : ENCRYPTION() elif sys.argv[1] == "-d" : DECRYPTION() elif sys.argv[1] == "-s" : SIGNING("clear") elif sys.argv[1] == "-ss" : SIGNING("separate") elif sys.argv[1] == "-v" : VERIFICATION() else: print "usage: pcp [-pure] -e|-d|-s|-ss|-v file|-pipe" print " pcp -wipe files" else: print "usage: pcp [-pure] -e|-d|-s|-ss|-v file|-pipe" print " pcp -wipe files" ################################################################ # Copyright 2003, Ralf Senderek # ################################################################ sys.exit(0) sig=""" -----BEGIN PGP SIGNATURE----- Version: 2.6.3in Charset: noconv iQEVAwUBP0fNrL6wVDeIE49tAQHmjAgAyetbOxRg8UsdnrJ+1OjPdpvwwdxJ8xeG KCv06kCdrpDqbZhDn4+GP10pjEjNnxwbCCEMJO6Hg2T2GeO366gTqof5pXJWvMu6 INnds8Eq0AsFEjRmTm/1smNafBaJ6vGue3EesFmjZkbZ+8dIWMajXDL0bFGKPotE uo4FIkUvxxCtxwGr2Zc/qp16aM2DnC3trKzyAuYLoMVXThM+6HnMnu9dRMN0lQ0F 1P8ch8ki01gu/yeWfYmE4u4RVTI72FrxB3Ay6bGgma1AxBn2z3Rp7MHcT9KrosGL TwdlrrLFNPuEyryV6H4XvrV7goZhIKop/T+DZiwPCdGhBXiIJLQMnQ== =Pa2F -----END PGP SIGNATURE----- """