Hi
Just written a small C++ program to try the Public & Private Key Algorithm process, the program seems to function properly as intended in that it decrypts a message sent from Bob using Alice's Public key.
#include <iostream>
using namespace std;
/***********************************************************
XOR Process
for both encryption/decryption processing
***********************************************************/
string XOR_Encryption(string toBeEncrypted, string sKey)
{
string sEncrypted(toBeEncrypted);
unsigned int iKey(sKey.length()), iIn(toBeEncrypted.length()), x(0);
for(unsigned int i = 0; i < iIn; i++)
{
sEncrypted[i] = toBeEncrypted[i] ^ sKey[x];
if(++x == iKey){ x = 0; }
}
return sEncrypted;
}
/***********************************************************
Main
***********************************************************/
int main()
{
/**
On Bob's PC
-----------
Bob wants to send Alice a message
*/
string message = "Hello Alice, this is a short message from Bob";
string Alices_PublicKey("AAAAB3NzaC1yc2EAAAABJQAAAIEAlzg30kazy6T+PeqjhFylhMUJNkK4AWU1kL0e2ZraqMw9eK/OzHONNky89oi6ibhn85o5ZOF83P4IJV5WiOrG3nyNif/rqV/Y2glpHodF2PLlWmAHd3bIcdrdnvXnGt70alzbXUPKbGiA2P9BMtmYNwBF/wVka3nx7pnxKmmOaS8=");
/**
Bob encrypts the message using Alice's Public key
*/
string encrypted_message = XOR_Encryption(message, Alices_PublicKey);
cout << "Bob's encrypted message reads as follows::" << encrypted_message << endl;
/**
On Alice's PC
-------------
Alice recieves the encrypted message from Bob
*/
string Alices_PrivateKey("B2odyv0xVcHpM7t1KaeEUd3KlaM3P+48o5ZdXOjWCn2chhiDQqjtHPZ30Icm8lbcmlHJwrCs4BRKmm4/56lDJbGotQwb+B3iQLKhBG61r/ilSV9FyNHH0t6XkDfbz1nXAU8TkXPrfqDVAenTjueEL+MVCREZRzr5O8NE9vTTQx/G8Yv8dGnLkjbcPUkaOdu23khGpKKcVvEM/TyVW9dClt94yy+LTn9+eEIBBUSbxQPzITIVHjHlhjnCQ+ear+JegXWqM58X7LaYEm0Ui35d0jwDKjH36XNugiwRcaJEQbyi1EwNvdZMzO7ckL+k2UEcp+0FbQwWFnaXTi7P8gebA3QJa1XqxZGPnDmfjEut4J/TuoHwWoPgpR5YssTh4F8UYEfUWxKr3AZHxywO9tVjuIwZ/jtVHWfARTv22zIslMrICR7cvj2RY7OpWPsefhpNA+PJktoF8LSDyNze2wCO5w==");
/**
According to the rules, certain process's should take place
for Alice to be able to successfully decrypt the message sent from bob
Step [1]
Alices should firstly XOR her Private key against her Public key
*/
string XOR_ed_keys = XOR_Encryption(Alices_PublicKey, Alices_PrivateKey);
/**
Step [2]
Then take the results from Step [1] XORed keys & XOR them against the
encrypted message from Bob
*/
string result = XOR_Encryption(encrypted_message, XOR_ed_keys);
/**
Step [3]
Decrypt the message using the results from Step [2] & XOR them
against Alice's Private key
*/
string decrypted_message = XOR_Encryption(result, Alices_PrivateKey);
/**
Finally Alice reads the message from Bob
*/
cout << "Bob's decrypted message reads as follows:: " << decrypted_message << endl;
return 0;
}
My understanding is that Public & Private Keys need to be paired in order to work properly, so I used a program called PuTTY to do just that.
Here the problem:
If I generate a second set of paired keys and substituted Alice's orignal Private Key with a new Private Key[Below] & still use the original Public Key the program still decrypts Bob's message, Why?
uDLtytuUhYPduFe3vO7sRxO2MJ2KwoB0Hc9GbPDWxt30IqV9TQhxe2vdMmCKILeB
D7BlYl3t5Vl0iu+aGOQ3OAbKkJJtzOZdkRbC/horVTxFbpOjbCWpMxruaoZdySgK
Q+LPMs0c1VMdESiMU4yIzRVjvGv9H13LIuB5S1s/ipc3R0ux9xW/n08t/UlOFUSu
SvmbPQ1rgCgY6S4aqXPkZjRKbP8Bv9zI3ZDE6kOGgUwtWNH+ITeTsMv/Fl6i9b6m
XEeHOHCsBymhVt+KkZVtrbL5Zsh7+Q3Y1sladjVii7T7zqUx4np4NVjcqivnwTPe
PumtKbrrzwQPPlgEIn3TdzTN/PB1fq46c6lTMj14a4izT5e1yIqMhxRajQTTd1Cz
ozfEvJhI8lPldxhortVO6J7rJMHc08I4XbBCWN5AcOBD+imkDkdthHqsXeChhCq0
wAu67lAKD5QrC8IlQ4Z5lQ==
I was on the understanding that one Private Key was unique to it's Public Key counter part.
Or am I simply missing something here?
Best Regards