Exponential Cipher Encryption Help Needed
Show older comments
I'm still very new to using matlab for programming functions and I'm not totally sure what I'm meant to be doing, however I tried my best to create a function to generate the keys needed for a pohlig hellman exponentiation cipher.
I think it covers all of the requirements I've been given, but with the addition of the multmod the loops don't ever stop giving me an answer.
Any help at all anyone can give would be much appreciated.
Must generate a random prime number, p, between 2^51 and 2^53 e must be less than, and share no common divisors with, p-1 d must be a random prime number less than p-1 and such that e*d = 1 mod (p-1)
If any more info or anything is needed just ask.
Thanks again
function [e,d,p] = GenerateKeys()
%GenerateKeys Generates keys for pohlig-hellman cipher
% Generate the primes e d and p, e being the encrypting exponent, d the
% decrypting exponent and p the modulus
z=2^53-1;
p=randi([2^51,z]);
while MillerRabin(p)==0
p=randi([2^51,z]);
x=p-1;
end
e=randi(x);
while rem(e,x)==0
e=randi(x);
end
[a,b,c]=gcd(e,x);
while a~=1
e=randi(x);
[a,b,c]=gcd(e,x);
d=mod(b,x);
while multmod(e,d,p)~=1
e=randi(x);
end
end
end
1 Comment
Walter Roberson
on 26 May 2011
multmod() is not a Mathworks routine, so we will need the code for it.
Answers (0)
Categories
Find more on Encryption / Cryptography in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!