Esempio n. 1
0
        genkey_rsa 47 61 publicKey.txt privateKey.txt
        """
        )
    else:

        if sys.argv[1] == "get_hash":

            # считать данные
            try:
                file = open(sys.argv[2], "r")
                text = file.read()
            finally:
                file.close

            # подсчитать хеш
            (h0, h1, h2, h3, h4) = SHA1.sha1(text)
            print("%8x%8x%8x%8x%8x" % (h0, h1, h2, h3, h4))

            # записть хеш в файл
            file = open(sys.argv[3], "w")
            file.write("%8x%8x%8x%8x%8x" % (h0, h1, h2, h3, h4))
            file.close()

        if sys.argv[1] == "check_hash":

            # читаем файл
            file = open(sys.argv[2], "r")
            text = file.read()
            file.close()

            # сгенерируем хеш
Esempio n. 2
0
         
         #инициализация 
         import  GetValuesForEC, EllipticCurve, SHA1, random
         ec_= GetValuesForEC.EC(int(sys.argv[3]))
         ec_.setAB((int(sys.argv[4]),int(sys.argv[5])))
         ec = EllipticCurve.EC(int(sys.argv[4]), int(sys.argv[5]), int(sys.argv[3]))
         g,_= ec.at(0)
         eg = EllipticCurve.ElGamal(ec, g)
         dsa = EllipticCurve.DSA(ec, g)
         
         # читаем файл
         file=open(sys.argv[2],"r")
         text=file.read()
         file.close()
         # сгенерируем хеш
         hash_text=int(''.join([str(hex(h)[2:]).replace("L","") for h in SHA1.sha1(text)]),16)
 
         # генерируем ЭЦП
         while(True):
             private_key = random.randrange(1,int(sys.argv[3])-1)
             if ec_.isPrime(private_key):
                 public_key = eg.gen(private_key)
                 print("Private key: %d" % private_key)
                 print("Public key: (%d,%d)" % public_key)
                 r = public_key[0] % int(sys.argv[3])
                 if r==0:
                     continue
                 else:
                     break
         #r = 20 # 53 5 17
         sig=dsa.sign(hash_text, private_key, r)