Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:15:31+00:00 2026-05-30T13:15:31+00:00

I want to encrypt a message such as ‘HELO1234 and then decrypt to get

  • 0

I want to encrypt a message such as ‘HELO1234 and then decrypt to get the original one.I have written RSA code in matlab which is not working correctly.

PARAMETER CALCULATION

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 ...
     && gcd(deckey,phi_n)~=1 ...
   &&gcd(enckey*deckey,phi_n)~=1)
    temp=1;
 else 
 temp=0;
  end
  end
end

ENCRYPTION PROCESS

 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

d

OUTPUT OF encryption process

k =

 0     1     1     0     1     0     1     0     0     0

prime_mat =

 2     3     5     7

p =

 7

q =

 2

n =

14

enckey =

 5

deckey =

 1

phi_n =

 6

len =

28

cipher_text =

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

DECRYPTION PROCESS

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)]

uint8(plain_text);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:15:32+00:00Added an answer on May 30, 2026 at 1:15 pm

    Don’t bother implementing it yourself. Writing crypto is hard and bugs have security consequences. Use a well-known library from a trusted vendor.

    In Matlab, you can call down to the standard Java cryptography classes included with the JVM bundled with Matlab. The Matlab code will look something like this.

    import javax.crypto.Cipher;
    
    plaintext = 'foobar';
    
    cipher = Cipher.getInstance('RSA');
    keygen = java.security.KeyPairGenerator.getInstance('RSA');
    keyPair = keygen.genKeyPair();
    cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPrivate());
    
    plaintextUnicodeVals = uint16(plaintext);
    plaintextBytes = typecast(plaintextUnicodeVals, 'int8');
    ciphertext = cipher.doFinal(plaintextBytes)'  %'
    
    % And back out
    cipher.init(Cipher.DECRYPT_MODE, keyPair.getPublic());
    decryptedBytes = cipher.doFinal(ciphertext);
    decryptedText = char(typecast(decryptedBytes, 'uint16'))'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use PBE to encrypt my data. So far, I have written
I'm struggeling with code from this page: http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php I want to send data from
I want to use RSA algorithm , for encrypt and decrypt messages. Now, as
I've written some abstractions for Crypto.Cipher.AES.encrypt/decrypt , and I want to write unit tests
i want to encrypt string in java and decrypt the same string in C#
I want my application to encrypt a user password, and at one time password
If I want to sign and encrypt a message using an X509 certificate, is
we have a project written in Delphi that we want to convert to C#.
I have a Credit Card Number in an XML Message and I want to
I want to encrypt some server data using .NET's RSACryptoServiceProvider and decrypt it when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.