Beruflich Dokumente
Kultur Dokumente
#include<bits/stdc++.h>
using namespace std;
int main(){
int z=29;
cin>>z;
int ar[z];
int full=(z*(z-1))/2,a=1,s;
for(int i=1;i<z;i++){
a=1;
s=0;
for(int j=0;j<z;j++) ar[j]=0;
for(int k=1;k<z;k++){
a=(a*i)%z;
ar[a]=1;
}
if(ar[0]==0){
for(int j=1;j<z;j++) s+=ar[j];
if(s==z-1) cout<<i<<endl;
}
}
return 0;
}
2. In Multiplicative group < Z421*,x >
a. Encrypt the Input: “Learning is Studying” (Consider ASCII Values) with Elgamal
CryptoSystem.
b. Decrypt the above generated Cipher.
#include<bits/stdc++.h>
using namespace std;
vector<int> c2;
for(int i=0;i<text.length();i++)
{
int temp=(power(e2,r,prime)*text[i])%prime;
c2.push_back(temp);
}
return c2;
}
int main()
{
cout<<"Input"<<endl;
int prime;
cin>>prime;
string text;
cin>>text;
vector<int> rootset;
getprimitiveroots(prime,rootset);
int n=rootset.size();
srand (time(NULL));
int e1=rootset[rand()%n];
int d=rootset[rand()%n];
int c1;
vector<int> ans=encryption(text,e1,d,prime,c1);
cout<<"Encrypted Text"<<endl;
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<endl;
string decrypted=decryption(ans,d,c1,prime);
cout<<"Decrypted Text"<<endl;
//cout<<ans<<endl;
cout<<decrypted<<endl;
}
3. Given the super increasing tuple b = [7, 11, 23, 43, 87, 173, 357], r = 41, and modulus n =
1001, write a program to encrypt and decrypt the letter “a” using knapsack cryptosystem. Use [7 6 5
1 2 3 4] as the permutation table.
#include<bits/stdc++.h>
using namespace std;
for(int i=6;i>=0;i--){
if(sdash>=b[i]){
tup[i] = 1;
sdash = sdash-b[i];
}
else tup[i] = 0;
}
for(int i=0;i<7;i++)
cout<<tup[i];
cout<<endl;
int a1[7];
for(int i=0;i<m;i++){
a1[i] = tup[perm[i]-1];
}
for(int i=0;i<7;i++)
cout<<a1[i];
cout<<endl;
int ascii = 0;
int j=0;
for(int i=6;i>=0;i--){
ascii += a1[i]*pow(2,j);
j++;
}
cout<<ascii<<endl;
cout<<(char)(ascii-97+'a')<<endl;
}