-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.py
68 lines (66 loc) · 1.46 KB
/
count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from Pyfhel import Pyfhel,PyCtxt,PyPtxt
import numpy as np
import time
he=Pyfhel()
he.contextGen(p=1179649,m=32768,flagBatching=True,fracDigits=20)
he.keyGen()
a=PyCtxt()
b=PyCtxt()
q=0
#加密文件
def PPctxt(name):
global panduan
panduan=name
fil=open(name)
lines=fil.readlines()
strr=''.join(lines)
arr=[]
for line in strr:
for ind in line:
arr.append(ind)
#arr.remove('\n')
brr=[]
for i in arr:
brr.append(ord(i))
crr=np.array(brr)
#列表数据转数组
err=he.encryptBatch(crr)
err.save(name)
global l
l=len(strr)
PPctxt('1.txt')
#搜索(单字母)
def count(name,zm,l1=None):
global c
c=None
global zmm
zmm=zm
if(len(zm)<2):
a.load(name,encoding='array')
b=np.zeros((l,),dtype=int)
d=ord(zm)
for i in range(l1,l):
#print(l1,l)
b[i]=d
#print(b)
b=he.encryptBatch(b)
c=he.sub(a,b)
result=c
else:
print('Error: Does not conform to be rule,the parameter size should be 1')
print(c)
return c
count('1.txt','iss',1)
def DecryptCount(name,n):
while(name==panduan and len(zmm)<2):
a=he.decryptBatch(c)
ii=0
a=a[:l]
for i in a:
if i==0:
ii=ii+1
print(zmm,':',ii,'次')
break
else:
print('Error:The name or the length of the input string is not corret and cannot be decrypt correctly')
DecryptCount('1.txt',1)