Note that there are some explanatory texts on larger screens.

plurals
  1. PORSA code in matlab
    text
    copied!<p>I want to encrypt a message such as <strong>'HELO1234</strong> and then decrypt to get the original one.I have written RSA code in matlab which is not working correctly.</p> <blockquote> <p>PARAMETER CALCULATION</p> </blockquote> <pre><code>temp=1; range=1:10; k=isprime(range) prime_mat=range(find(k)) p=randsample(prime_mat,1); q=randsample(prime_mat,1); if(p~=q) n=p*q; phi_n=(p-1)*(q-1); u=1:phi_n -1; end while temp enckey=randsample(u,1); deckey=randsample(u,1); if(enckey~=deckey) if(gcd(enckey,phi_n)~=1 ... &amp;&amp; gcd(deckey,phi_n)~=1 ... &amp;&amp;gcd(enckey*deckey,phi_n)~=1) temp=1; else temp=0; end end end </code></pre> <blockquote> <p>ENCRYPTION PROCESS</p> </blockquote> <pre><code> char t= 'hello123'; t=uint8(t); len=length(t) pow=[]; cipher_text=[]; for i=1:len pow=[pow;t(i).^(enckey)]; %each element of the pt matrix(plain text) is raised to the power of encryption key(enc_key) and stored in pow matrix(power matrix) cipher_text=[cipher_text;mod(pow(i),n)];% cipher text is calculate </code></pre> <p>d</p> <blockquote> <p>OUTPUT OF encryption process</p> </blockquote> <p>k =</p> <pre><code> 0 1 1 0 1 0 1 0 0 0 </code></pre> <p>prime_mat =</p> <pre><code> 2 3 5 7 </code></pre> <p>p =</p> <pre><code> 7 </code></pre> <p>q =</p> <pre><code> 2 </code></pre> <p>n =</p> <pre><code>14 </code></pre> <p>enckey =</p> <pre><code> 5 </code></pre> <p>deckey =</p> <pre><code> 1 </code></pre> <p>phi_n =</p> <pre><code> 6 </code></pre> <p>len =</p> <pre><code>28 </code></pre> <p>cipher_text =</p> <pre><code>3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 </code></pre> <blockquote> <p>DECRYPTION PROCESS</p> </blockquote> <pre><code>plain_text=[]; pow1=[]; len1=length(cipher_text); for i=1:len pow1=[pow1;cipher_text(i).^(deckey)] plain_text=[plain_text;mod(pow1(i),n)] </code></pre> <p>uint8(plain_text);</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload