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 7527069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:00:53+00:00 2026-05-30T04:00:53+00:00

I am implementing my own RSA algorithm in ruby to learn more about the

  • 0

I am implementing my own RSA algorithm in ruby to learn more about the algorithm.
It is almost working, but when I decrypt it a few numbers don’t decrypt but most do.
Why would this be?

For the given plaintext:
[ 42, 24, 424, 224, 421, 321]

The ciphertext is:
[1239,1263,1495,1349,208,1878]

Which when decrypted is:
[42,690,424,779,421,321]

This is the problem. Why is it happening?

These values are used to produce the keys (The method call is at the end of the program)

p = 51
q = 37
e = 223
n = 1887
phiN = 1800 (coprime with d)
d = 1687




class RSA
#edited to be concise, such as omitting initialize()

def encrypt(plainText)
index = 0
puts 'encrypt in is ', plainText
    plainText.each do |i|
    plainText[index] = ((i**(@e)) % @n )
    index+=1
    end
 puts  'ciphertext is '
puts plainText
return plainText
end


def decrypt(cipherText)
puts 'decrypt in is ', cipherText
index = 0
    cipherText.each do |i|
    cipherText[index] = ((i**(@d)) % @n )
    index+=1
    end
puts 'plaintext is '
puts cipherText
return cipherText
end


def calcD()
@d=1
begin 
s = (@d*@e)% @phiN;
@d+=1
end while not s==1
@d -= 1
#puts 'd is ', @d
end


end # class

message = RSA.new(51,37,223,[ 42, 24, 424, 224, 421, 321])
  • 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-30T04:00:56+00:00Added an answer on May 30, 2026 at 4:00 am

    51 is not a prime.

    Since that is one of the assumptions for the RSA algorithm, it should be no surprise that it fails to work.

    Since your p is not a prime phi(n)!=(p-1)(q-1).

    You could make it work by noticing that phi(51*37)=phi(3*17*37)=(3-1)(17-1)(37-1)=1152 and then calculating a working d=e^-1 (mod phi(n)) = 223^-1 (mod 1152) = 31, but I would recommend just using a prime p instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I get info about implementing my own methods that have the ellipsis
I am implementing my own ArrayList for school purposes, but to spice up things
Working on implementing my own BST in C++ for the experience of dealing with
I'm currently working on implementing my own Trie in Scala (for learning/hobby purposes), and
I'm implementing my own named pipe Client/Server class, but I'm getting too much troubles
I'm just reading about implementing my own HTTP handler for ASP.NET 4.0 and IIS7.
I am implementing my own shell. But to supprt for command history, I need
I am currently (don't ask why :P) implementing my own versions of malloc() and
Microsoft like implementing their own versions of popular open-source frameworks and assemblies, for example:
I've been implementing my own version of a red-black tree, mostly basing my algorithms

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.