SHARE
TWEET

Untitled

a guest Jun 25th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. from math import *
  3. samo = "aeiouAEIOU"
  4. spol = "BCDFGHJKLMNPQRSTVXZWY"
  5.  
  6. def fme(a, k, n):
  7.  
  8.     b = bin(k)[2:] # list of bits
  9.     m = len(b)
  10.     r = 1 # result
  11.     x = a % n
  12.  
  13.     for i in range(m - 1, -1, -1):
  14.         if b[i] == '1':
  15.             r = r * x % n
  16.  
  17.         x **= 2
  18.         x  %= n
  19.  
  20.     return r
  21.  
  22.  
  23.  
  24. def rozklad(x):
  25.     if x<=0:
  26.         return 0
  27.     i=2
  28.     e=floor(sqrt(x))
  29.     r=[] #używana jest tablica (lista), nie bepośrednie wypisywanie
  30.     while i<=e:
  31.         if x%i==0:
  32.             r.append(i)
  33.             x/=i
  34.             e=floor(sqrt(x))
  35.         else:
  36.             i+=1
  37.     if x>1: r.append(x)
  38.     r = list(dict.fromkeys(r))
  39.     return r
  40.  
  41.  
  42.  
  43. def count_n(text):
  44.     n1 = 0
  45.     n2 = 0
  46.     sp = 0
  47.     for t in text:
  48.         if t in samo:
  49.             n1+=1
  50.         elif t.upper() in spol:
  51.             n2+=1
  52.         elif t == " ":
  53.             sp+=1
  54.     return n1, n2, sp
  55.  
  56. def JHA(text,p,q):
  57.     n1,n2,sp = count_n(text)
  58.     pot =  7*n1 - 3*n2 +sp*sp
  59.     #print(pot)
  60.     if(pot<0):
  61.         b = (1/(q%p)) %p
  62.         print(b)
  63.         return fme(b,-1*pot,p)
  64.     return fme(q,pot,p)
  65.    
  66. print(JHA("AaBBB BBB cdcd",2741,137))
  67.  
  68. p = int(input("podaj p:"))
  69. g = input("podaj g: ")
  70. k = input("podaj k: ")
  71. r = input("podaj r: ")
  72.  
  73. q = sorted(rozklad(p-1))[-1]
  74. with open('tekst_krotki1.txt') as file:
  75.     line = file.read()
  76. print('q : ',q)
  77. print("skrót : ", JHA(line,p,q))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top