-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (54 loc) · 858 Bytes
/
main.js
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
function checkeasy(num) {
for (let i = 3; i <= Math.sqrt(num); i++){
if ((num % i) == 0){
return false
}
}
return true
}
function isCoprime (a, b) {
var num;
while ( b ) {
num = a % b;
a = b;
b = num;
}
if (Math.abs(a) == 1) {
return true;
}
return false;
}
let p = 23
let q = 29
let n = q * p
let f = (p-1) * (q-1)
let r = false
let e
for (e = 2; r != true; e++){
if(e < f){
if(checkeasy(e) == true){
if(isCoprime (e, f)){
r = true
e++
}
}
}
}
let d = 1
while((d*e)%f != 1){
d++
}
let str = 'Bom'
console.log(str)
let P = []
for(let i = 0; i < str.length; i++){
P.push(str.codePointAt(i))
}
console.log(P)
let shifr = []
for(let i = 0; i < str.length; i++){
shifr.push(Number(BigInt(P[i])**BigInt(e)%BigInt(n)))
}
console.log('shifr =',shifr)
console.log('d =',d)
console.log('n =',n)