Advertisement
woidmal

Untitled

Dec 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var tocjent;
  2. var public_key;
  3. var private_key;
  4.  
  5. function calculate()
  6. {
  7.    number1 = document.getElementById("first-prime").value;
  8.   number2 = document.getElementById("second-prime").value;
  9.   result = number1*number2;
  10.  document.getElementById("product-span").innerHTML=result;
  11.  tocjent = (number1-1)*(number2-1);
  12.  document.getElementById("tocjent-span").innerHTML=tocjent;
  13. }
  14.  
  15. function check()
  16. {
  17.  public_key = 5;
  18.  while(euklides(tocjent, public_key)!=1)
  19.   {
  20.    public_key++;
  21.   }
  22.   document.getElementById("check-span").innerHTML = public_key;
  23.  temp = tocjent;
  24.  i = 1;
  25.  while((temp+1)%public_key!=0)
  26.   {
  27.    i++;
  28.    temp = temp * i;
  29.   }
  30.  private_key=(temp+1)/public_key;
  31.  document.getElementById("private-key").innerHTML=private_key;
  32. }
  33.  
  34. function euklides(a, b)
  35. {
  36.    while(b!=0)
  37.    {
  38.      c=a%b;
  39.      a=b;
  40.      b=c;
  41.    }
  42.    return a;
  43. }
  44.  
  45. function power_mod(a,b,c)
  46. {
  47.  temp=1;
  48.  a = a%c;
  49.  for(i=1;i<=b;i++)
  50.   {
  51.     temp=temp*a;
  52.     temp=temp%c;
  53.   }
  54.  return temp;
  55. }
  56.  
  57. function crypt()
  58. {
  59.     pt = document.getElementById("plaintext").value;
  60.     pp = document.getElementById("product-prime").value;
  61.     pk = document.getElementById("de-public-key").value;
  62.     document.getElementById("code-text").innerHTML=(power_mod(pt,pk,pp));
  63. }
  64.  
  65. function decrypt()
  66. {
  67.  prk=document.getElementById("en-private-key").value;
  68.  ct=document.getElementById("en-code-text").value;
  69.  pprime=document.getElementById("en-product-prime").value;
  70.  document.getElementById("en-code-result").innerHTML=(power_mod(ct,prk,pprime));
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement