Exponential Cipher Encryption Help Needed

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

Walter Roberson
Walter Roberson 2011년 5월 26일
multmod() is not a Mathworks routine, so we will need the code for it.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

태그

질문:

Rob
2011년 5월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by