Esempio n. 1
0
def check_CP():
    data = loadCP()
    if data['hesh'] == '1':
        H = SHA.sha256(data['message'])
    elif data['hesh'] == '2':
        H = SHA.sha512(data['message'])
    elif data['hesh'] == '3':
        H = stibog.Main(data['message'], 256)
    elif data['hesh'] == '4':
        H = stibog.Main(data['message'], 512)
    R_test = (int(
        fun.obrat(pow(data['U'] * data['L'], data['L'], data['p']), data['p']))
              * pow(data['a'], data['S'], data['p'])) % data['p']
    kon = data['message'] + str(R_test) + str(data['U'])
    if data['hesh'] == '1':
        E_test = SHA.sha256(kon)
    elif data['hesh'] == '2':
        E_test = SHA.sha512(kon)
    elif data['hesh'] == '3':
        E_test = Stibog.Main(kon, 256)
    elif data['hesh'] == '4':
        E_test = Stibog.Main(kon, 512)

    if data['E'] == E_test:
        print(True)
    else:
        print(False)
Esempio n. 2
0
def FBI_OPEN_UP():
    cp_list = []
    with open("ЦП.txt", "r") as prifile:
        gamma, delta = (prifile.read().split())
    with open("Cp_Document.txt", "r") as pubfile:
        cp_list = pubfile.read().split('\n')
    hm = cp_list[1]
    alpha, beta, p = cp_list[3].split()
    mes = cp_list[13]
    alpha, beta, p, gamma, delta = int(alpha), int(beta), int(p), int(
        gamma), int(delta)
    if PKCS_7[1] == hm:
        hesh = int(SHA.sha256(mes), base=16)
    elif PKCS_7[1] == hm:
        hesh = int(SHA.sha512(mes), base=16)
    elif PKCS_7[1] == hm:
        hesh = int(STR.Stribog(mes, 256), base=16)
    elif PKCS_7[1] == hm:
        hesh = int(STR.Stribog(mes, 512), base=16)
    print(
        pow(beta, gamma, p) * pow(gamma, delta, p) % p, '==',
        pow(alpha, hesh, p))
    if pow(beta, gamma, p) * pow(gamma, delta, p) % p == pow(alpha, hesh, p):
        print("true")
    else:
        print("false")
Esempio n. 3
0
def hesh_message(message: str, type_hesh: int):
    if type_hesh == 1:
        H = SHA.sha256(message)
    elif type_hesh == 2:
        H = SHA.sha512(message)
    elif type_hesh == 3:
        H = Stribog.Stribog(message, 256)
    elif type_hesh == 4:
        H = Stribog.Stribog(message, 512)
    else:
        H = '0'
    return H
Esempio n. 4
0
def encryptRSAWithOAEP(message):
    global K0,K1,N,e,n
    valueMessage = long(message, 16)
    r = random.randrange(1 << (K0-1), (1 << K0) - 1)
    keccak = sha.sha3_384(hex(r))
    Gr = long(keccak.hexdigest(), 16) # 384 bits
    X = (valueMessage << K1) ^ Gr
    keccak = sha.sha3_256(hex(X))
    Hx = long(keccak.hexdigest(), 16) # 256 bits
    Y = r ^ Hx
    res = (X << K0) + Y
    # RSA encryption
    encrypt = pow(res, e, n)
    return encrypt
Esempio n. 5
0
def decryptRSAWithOAEP(encrypt):
    global K0,K1,N,d,n
    # RSA decryption
    encryptValue = pow(encrypt, d, n)
    
    Y = encryptValue % (1 << K0)
    X = encryptValue >> K0
    keccak = sha.sha3_256(hex(X))
    Hx = long(keccak.hexdigest(), 16) # 256 bits
    r = Y ^ Hx
    keccak = sha.sha3_384(hex(r))
    Gr = long(keccak.hexdigest(), 16) # 384 bits
    message = X ^ Gr
    message >>= K1
    return hex(message)
Esempio n. 6
0
def hesh_choose(message, type):
    if type == '1':
        H = SHA.sha256(message)
        return H
    elif type == '2':
        H = SHA.sha512(message)
        return H
    elif type == '3':
        H = Stibog.Main(message, 256)
        return H
    elif type == '4':
        H = Stibog.Main(message, 512)
        return H
    else:
        print('Error')
        return 0
Esempio n. 7
0
def FBI_OPEN_UP(m=512):
    PKS=list()
    with open("publick.txt","r") as priv:
        Bi=priv.read().split("\n")
        n=Bi[1]
        Bi=Bi[0].split()
    with open("Cp.txt","r") as priv:
        s=priv.read().split()
        t=s[1]
        s=s[0]
    with open("Cp_Document.txt","r") as Cp_D:
        for i in Cp_D:
            PKS.append(i)
    M=PKS[13]
    w=int(t)*int(t)
    j=1
    i=0
    k=0
    z=Pim(Bi,s,n)
    w=int((w*z)%int(n))
    print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    print(w)
    H=SHA.sha512(str(M)+str(w))
    H = str(convert_base(H, 2, 16))
    while len(H)!=512:
        H="0"+H
    print(len(s))
    print(len(H))
    print("s = "+str(s))
    print("s'= "+str(H))
    if s==H:
        print(True)
    else:
        print(False)
Esempio n. 8
0
def install(macid):
    print('Enter admin pendrive to continue')
    try:
        driveletter = drive()
        os.chdir('{}:\\bankadmin'.format(driveletter))
    except:
        print('Access denied')
    try:
        with open('Password.txt') as passw:
            passwhash = passw.read()
            passw.close()
        passinput = getpass('Enter password: '******'mkdir "Cashvault"')
            os.chdir('Cashvault')
            os.system('type nul > cash.txt')
            with open('cash.txt', 'w') as vault:
                vault.write('0')
                vault.close()
            os.chdir(cwd)
            os.system('type nul > macid.info')
            with open('macid.info', 'w') as f:
                f.write(macid)
                f.close()
            os.system('attrib +s +h macid.info')
            os.system('attrib +s +h Cashvault')
            print('$AdminShell> Machine Installation was successful')
            sys.exit()
    except:
        pass
Esempio n. 9
0
def LEAD_3(p, q, a, R_l: list, M, U, type):
    T = random.randint(2, q - 1)
    R_lead = pow(a, T, p)
    R = 1
    for i in range(len(R_l)):
        R = R * R_l[i]
    R = R_lead * (R % p)
    E = M + str(R) + str(U)
    if type == '1':
        E = SHA.sha256(E)
        return E, T  # Лидер отправляет каждому пользователю E, лидер T не передаёт, но тут передаёт
    elif type == '2':
        E = SHA.sha512(E)
        return E, T
    elif type == '3':
        E = Stibog.Main(E, 256)
        return E, T
    elif type == '4':
        E = Stibog.Main(E, 512)
        return E, T
Esempio n. 10
0
def vaultrefill(OTP):
    while True:
        OTPpass = input('Enter OTP to refill: ')
        if str.encode(SHA.sha_encode(OTPpass)) == OTP:
            with open('Cashvault\\cash.txt') as vault:
                cash = int(vault.read())
                cash += 5000000
                vault.close()
            with open('Cashvault\\cash.txt', 'w') as vault:
                vault.write(str(cash))
                vault.close()
            break
Esempio n. 11
0
def search_for_collisions():
    dictionary = dict()
    for i in range(0,
                   110000):  # there's a 75% chance of finding a collision here
        message = create_random_message(random.randint(1, 100))
        cut_digest = get_32_digest(SHA.sha(message))
        collision_plain = dictionary.get(cut_digest, '-1')
        if collision_plain != '-1' and collision_plain != message:
            print('Collision found:')
            print(collision_plain, '\nand\n', message,
                  '\nhave the same first 32 bits in the digest: ', cut_digest)
            return i
        dictionary[cut_digest] = message
    return 110000
Esempio n. 12
0
def FBI_OPEN_UP():
    flag = True
    PKCS_7 = ""
    sor = ""
    while flag:
        task = input("Pleas enter file with cp with .txt\n>> ")
        try:
            with open(task, "r") as cp_file:
                PKCS_7 = cp_file.read().split("\n")
            with open("ЦП.txt", "r") as cp_file:
                sor = cp_file.read()
                flag = False
                break
        except FileNotFoundError:
            print("cant find file, please try new name write\n")
    mes = PKCS_7[13]
    s = int(PKCS_7[10], 16)
    e = PKCS_7[3].split()
    n = e[1]
    e = e[0]
    if PKCS_7[1] == "SHA256":
        hm = SHA.sha256(mes)
    elif PKCS_7[1] == "SHA512":
        hm = SHA.sha512(mes)
    elif PKCS_7[1] == "STR256":
        hm = STR.Stribog(mes, 256)
    elif PKCS_7[1] == "STR512":
        hm = STR.Stribog(mes, 512)
    hmshtrix = pow(s, int(e), int(n))
    print("\nResult - " + "None\n" + "Algorithm hash - " + PKCS_7[2] +
          "\nAlgoritm CP - " + PKCS_7[9] + "\nAuthor - " + PKCS_7[6] +
          "\nTime create CP - " + PKCS_7[11] + "\n")
    print("ЦП = " + str(sor))
    print("Cp_s = " + str(s))
    # print("NC = "+str(hex(int(hmshtrix))))
    print("NC = " + str(int(hmshtrix)))
Esempio n. 13
0
def Cp(Bi,n,Ai,M):
    n=int(n)
    r=random.randint(1,n)
    u=pow(r,2,n)
    H=SHA.sha512(str(M)+str(u))
    s=convert_base(H, 2, 16)
    while len(s)!=512:
        s="0"+s
    z=1
    print("s  = " + str(len(s)))
    print(u)
    z=Pim(Ai,s,n)
    t=int((r*z))
    with open("Cp.txt","w") as cp:
        strin=str(s)+" "+str(t)
        cp.write(strin)
    return s
Esempio n. 14
0
def n_iteration(M, method):
    Hm = M
    n = randint(2, 100)
    HM_list = list()
    if method == 1:
        for i in range(1, n):
            Hm = SHA.sha512(Hm)
            HM_list.append(Hm)
    elif method == 2:
        for i in range(1, n):
            Hm = STR(Hm, 512)
            HM_list.append(Hm)
    with open("HnList.txt", "w") as txt:
        strin = ""
        for i in HM_list:
            strin = strin + i + "\n"
        if method == 1:
            strin = strin + "SHA 0"
        elif method == 2:
            strin = strin + "STR 0"
        txt.write(strin)
Esempio n. 15
0
def autoriz(KeyWord):
    with open("HnList.txt", "r") as txt:
        hash_list = txt.read().split("\n")
    type = hash_list[-1].split()
    type_hash = type[0]
    num_enters = int(type[1])
    if num_enters >= len(hash_list) - 5:
        choose = input(
            "Need generate new password. Do it now?\nYes or No?\n>>")
        if "Yes" == choose:
            n_iteration()
        elif "No" == choose:
            pass
    Hm = KeyWord
    if type_hash == "SHA":
        for i in range(0, int(num_enters) + 1):
            Hm = SHA.sha512(Hm)
        #if num_enters==0 or num_enters==1:
        #    Hm = SHA.sha512(Hm)
    elif type_hash == "STR":
        for i in range(1, int(num_enters) + 1):
            Hm = STR(Hm, 512)
        #if num_enters==0 or num_enters==1:
        #    Hm = SHA.sha512(Hm)
    if Hm == hash_list[num_enters]:
        print("Success")
        with open("HnList.txt", "w") as txt:
            strin = ""
            for i in hash_list:
                strin = strin + i + "\n"
            if type_hash == "SHA":
                strin = strin + "SHA " + str(num_enters + 1)
            elif type_hash == "STR":
                strin = strin + "STR " + str(num_enters + 1)
            txt.write(strin)
            return Hm
    else:
        print("bad try")
        return False
Esempio n. 16
0
    def adminaccess(self):
        print('Enter admin pendrive to continue')
        cwd = os.getcwd()
        while True:
            try:
                driveletter = self.drive()
                os.chdir('{}:\\bankadmin'.format(driveletter))
                with open('Password.txt') as passw:
                    passwhash = passw.read()
                    passw.close()

                passinput = getpass('Enter password: ')
                if SHA.sha_encode(passinput) == passwhash:

                    self.access = True
                else:
                    pass
                if self.access:
                    os.chdir(cwd)
                    break
            except:
                pass
Esempio n. 17
0
         with open("publick.txt", "r") as pub_k:
             Bi = pub_k.read().split("\n")
             n = Bi[1]
             Bi = Bi[0].split()
             PKCS_7[3] = str(n)
     except FileNotFoundError:
         print("Need generate keys. Please, do it and try later\n")
         break
     print("\nstart cp\priv")
     cp = Cp(Bi,n,Ai,mes)
     PKCS_7[6] = input("Enter you Name and Fname pleas ( Name Fname)\n>> ")
     SignVal = hex(int(cp))
     PKCS_7[10] = SignVal[2:]
     PKCS_7[11] = date.today()
     if PKCS_7[1] == "SHA256":
         PKCS_7[12] = SHA.sha256(mes + cp)
     elif PKCS_7[1] == "SHA512":
         PKCS_7[12] = SHA.sha512(mes + cp)
     elif PKCS_7[1] == "STR256":
         PKCS_7[12] = STR.Stribog(mes + cp, 256)
     elif PKCS_7[1] == "STR512":
         PKCS_7[12] = STR.Stribog(mes + cp, 512)
     with open("Cp_Document.txt", "w") as doc:
         for i in PKCS_7:
             stri = ""
             stri = stri + str(i) + "\n"
             doc.write(stri)
         doc.write(mes)
 elif point == "4":
     FBI_OPEN_UP()
 elif point == "5":
Esempio n. 18
0
def login():
    username = input('Enter your Username: '******'loginreq {}'.format(username).encode())
    permission = s.recv(100).decode('utf-8')
    if permission == '#a':
        print('(Entered characters will not be printed!!)')
        password = getpass('Enter your Password: '******'utf-8')
        if permission == '#a':
            s.send(' '.encode())
            userdetails = []
            x = s.recv(65536).decode('utf-8').replace("Decimal('", '')
            x = x[:-3] + ']'
            userdetails = eval(x)

            while True:
                usercash = int(userdetails[3])

                print('Your Cash: {}'.format(str(usercash)))
                print('Enter your choice: ')
                print('1. Withdraw')
                print('2. Deposit')
                print('3. User Profile')
                print('4. Log Out')

                opt = input('> ')
                if opt == '1':
                    while True:
                        try:
                            cashw = int(
                                input(
                                    'Enter the money you want to withdraw: '))
                        except:
                            print('Enter an integer only')
                        if cashw <= usercash and cashw <= cash():
                            s.send('withdrawal {} {} {}'.format(
                                userdetails[0], userdetails[2],
                                str(cashw)).encode())
                            if s.recv(100).decode('utf-8') == '#d':
                                print('{} rupees has been withdrawn'.format(
                                    str(cashw)))
                                cashwd(int('-{}'.format(cashw)))
                            break
                        else:
                            print(
                                'Entered amount is more than your balance or ATM vault has not enough money'
                            )
                elif opt == '2':
                    try:
                        cashd = int(
                            input('Enter the money you want to deposit: '))
                    except:
                        print('Enter an integer only')
                    s.send('depositreq {} {} {}'.format(
                        userdetails[0], userdetails[2], str(cashd)).encode())
                    if s.recv(100).decode('utf-8') == '#d':
                        print('{} rupees has been deposited'.format(
                            str(cashd)))
                        cashwd(int(cashd))
                elif opt == '3':
                    s.send('profreq {}'.format(userdetails[1]).encode())
                    print(s.recv(65535).decode('utf-8'))
                elif opt == '4':
                    break
                else:
                    continue
                x = s.recv(65536).decode('utf-8').replace("Decimal('", '')
                x = x[:-3] + ']'
                userdetails = eval(x)
        else:
            print('Wrong Password')
    else:
        print('Wrong Username')
Esempio n. 19
0
pfmt = 'png'

if __name__ == '__main__':

    import os, sys
    opt = sys.argv[1]  # CalcHC, PlotHC, Disaggregation

    if opt == 'CalcHC':
        #IMRs = ['CyberShake','CB08','BA08','CY08','AS08']
        IMR = sys.argv[2]

        IMLs = np.arange(0.01, 3, 0.2)  # in (g)
        P = SHA.PSHA(ERF=ERF,
                     IMR=IMR,
                     SourceType=SourceType,
                     ERFinfo=ERFinfo,
                     Ti=Ti)

        SiteData = datapth + 'Sites/cs_site_types.txt'
        P.HazardCurveCalc(IMLs, SiteInfo, SiteData, MetaPth=MetaPth)

    if opt == 'PlotHC':

        IMR = sys.argv[2]
        SiteName = SiteInfo['SiteName']
        plotpth = plotpth + '/%s' % SiteName
        if not os.path.exists(plotpth):
            os.mkdir(plotpth)

        # Plot Comparison of Hazard Curves (with CyberShake)
Esempio n. 20
0
def new_g(w: str, p: int):
    g = SHA.sha512(w)
    g = int(g, 16)
    g = g % p
    return g