Posts tagged "cipher"

Q&A: C++ Multidimensional array problem with Playfair cipher?


by Delwin Steven Campbell

Question by MAXimum: C++ Multidimensional array problem with Playfair cipher?
The assignment directions

The ‘playfair square’ is a digraphic matrix cipher. Digraphic means that it breaks its input into 2 character blocks and processes each block as a unit.

The matrix, like the sample below, is a 5×5 matrix with a 25 letter alphabet laid out in it in some mixed up order.

L M N O P
A B C D E
V W X Y Z
Q R S T U
F G H I K

For the sake of this, I will talk about “encryption.” However, decryption is just the opposite. REMEMBER: this problem explanation presents the encryption task. You are to write a DECRYPTION program (that is a program that given the encrypted input below, decrypts it to reveal the secret message) If you need a better explanation, look it up online, I can’t post more on here due to character limit.

YI UB EB IS KC SP UB EB FC AM CU QD SX

My issues

Once again, my teacher is leaving me to piece a number of puzzles together, but things like the current assignment at hand is something I was never really taught. No examples of a similar program were given either in my book or by my teacher. I’m not sure if I even made the matrix correctly or if there is an easier way to make it. I guess my biggest problem is comparing each pair with the matrix while incrementing the multi-dimensional array’s elements at the same time while using if-else statements.

Just as a sign that the output is correct for anyone who solves the program, the deciphered output should be “TO RE AC HT HE UN RE AC HA BL ES TA RX”, which is “To reach the unreachable star” in regular ol’ English. I figured this out using a piece of paper and the “fairplay” method.

If you don’t find the explanation of the “fairplay” very clear, you can look it up online. There are number of better explanations and illustrations out there.

The following program has some obvious flaws in it, namely the portions within the if-else statements that I am pretty sure are way off the mark. There is where I am having trouble, naturally.

Thanks in advance.

My program so far
:#include
using namespace std;

//begin program,’
int main()
{
//declare multi-dimensional array with 5×5 matrix for ciphering
char cipherArray[5][5];
//use char input array containing “YI UB EB IS KC SP UB EB FC AM CU QD SW”
char inputArray[] = {‘Y’,'I’,'U’,'B’,'E’,'B’,'I’,'S’,'K’,'C’,'S’,'P’,'E’,'B’,'A’,'M’,'C’,'U’,'Q’,'D’,'S’,'W’};
//use char output
char outputArray[50];
int size = 0, size1 = 0, size2 = 0, temp;
cipherArray[1][1] = ‘L’, cipherArray[1][2] = ‘M’, cipherArray[1][3] = ‘N’, cipherArray[1][4] = ‘O’, cipherArray[1][5] = ‘P’;
cipherArray[2][1] = ‘A’, cipherArray[2][2] = ‘B’, cipherArray[2][3] = ‘C’, cipherArray[2][4] = ‘D’, cipherArray[2][5] = ‘E’;
cipherArray[3][1] = ‘V’, cipherArray[3][2] = ‘W’, cipherArray[3][3] = ‘X’, cipherArray[3][4] = ‘Y’, cipherArray[3][5] = ‘Z’;
cipherArray[4][1] = ‘Q’, cipherArray[4][2] = ‘R’, cipherArray[4][3] = ‘S’, cipherArray[4][4] = ‘T’, cipherArray[4][5] = ‘U’;
cipherArray[5][1] = ‘F’, cipherArray[5][2] = ‘G’, cipherArray[5][3] = ‘H’, cipherArray[5][4] = ‘I’, cipherArray[5][5] = ‘K’;
//use for-statement to check input array with cipher array
for (size = 0; size < 23; size + 2)
{
inputArray[size]=cipherArray[size1][size2];
inputArray[size + 1]=cipherArray[size1][size2];
//within for-statement create if-else statements for special cases
//if pair is in same row move one space left in the cipher array. Use wrap around feature
if (size == size + 1 || size == size - 1)
{
size1++;
}
//if pair is on same column move one space down in the cipher array. Use wrap around feature
else if (size == size + 1 || size == size - 1)
{
size2++;
}
//if pair is the same letter move one space left as if on the same row
else if (size == size + 1 || size == size - 1)
{
size1++;
}
//else the pair is boxed. Swap sizes with column number of counterpart and remain on the same row.
else
{
temp = size1;
size1 = size2;
size2 = temp;
}
}
//set output array equal to deciphered input array
outputArray[size]=inputArray[size];
//print output array to screen
for (size = 0; size < 23; size + 2)
cout << outputArray[size] << outputArray[size+1] << " &qu

Best answer:

Answer by mdigitale
First of all, you may want to double check your cipher-text — I believe your test message, TOREACHTHEUNREACHABLESTARX
would be enciphered as:
IDUBBAISKCSPUBBAFCAMCUQDSW

If I was writing a decryption routine for this, here is the pseudo code approach I would probably take:

1. Define key matrix (read from user or define static in the code)
2. Obtain the cipher text from the user
3. Get first two letters from cipher text (a,b)
4. Find a in key matrix. Note matrix coordinates ax, ay.
5. Find b in key matrix. Note matrix coordinates bx, by.
6. Does ax == bx? If so, then execute the column transformation.
7. Else does ay == by? If so, then execute the row transformation.
8. Else execute the rectangle transformation.
9. Get next 2 letters in cipher text. Goto (4).

column transformation:
sub one from the ay coordinate, ensure >= 0. If not, ay = 4. Lookup key[ax,ay]
sub one from the by coordinate, ensure >= 0. If not, by = 4. Lookup key[bx,by]
row transformation:
sub one from ax coordinate, ensure >= 0. If not, ax = 4. Lookup key[ax,ay]
sub one from bx coordinate, ensure >= 0. If not, bx = 4. Lookup key[bx, by]

rectangle transformation:
temp = ax;
ax = bx
bx = temp
Lookup key[ax, ay]
Lookup key[bx, by]

What do you think? Answer below!

Be the first to comment - What do you think?
Posted by admin - February 3, 2012 at 11:10 am

Categories: Internet Access   Tags: , , , , , , , ,

T6 Encryption

An encryption algorithm I wrote a few months ago. There are 85 possible outputs for every message.

youtube: 24469666875366874713617
youtube: 22667865073565072535599
youtube: 26071268476968475879633
youtube: 20465662871362870313577
youtube: 21566763972463971424588

Duration : 0:1:44

Read more…

Be the first to comment - What do you think?
Posted by admin - August 31, 2010 at 8:25 pm

Categories: Message Encryption   Tags: , , , , , , , , , , , , , , , , , , , , ,

Trapeze Networks Introduction to Wireless LANs course

Trapeze Networks Introduction to Wireless LANs course recording, part 5: WLAN Coverage

This is a ‘teaser’ for the full course cut to 10 minutes. The full version can be viewed by contacting your local Trapeze Networks Sales or Training

representative. Go to the Trapeze Networks website at http://www.trapezenetworks.com for contact details and details of our other training packages

Duration : 0:10:8

Read more…

Be the first to comment - What do you think?
Posted by admin - August 21, 2010 at 1:11 am

Categories: Message Encryption   Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

How To Send Secret Messages

Download program here:

http://www.encryptionanddecryption.com/download.html

WARNING: When you copy or paste the cyphertext to or from YouTube, YouTube adds extra spaces between some of the characters. As such, the decryption WON’T WORK unless you delete all the extra spaces that YT adds. I don’t know why it does that. It distorts the text and kinda ruins the fun. There shouldn’t be any spaces between the characters of the cyphertext. The decryption won’t work if there is.

Decrypt my secret message:

D2FE056BABA1DF67E0F4AF3F401F123D4D753D730E5584AFA5508F2BE8BA390F96613E8C8C75B648FE77F1D96F8C8F6F3B7CCB6E3AA6FE8A75CBB5FBB8C1D8414257*7633*FD70A5A7537E2706B0FA9839ACBE9D2D69EB04961EA656B1F85528528D4BB6982*fyAgJUscItv9W4NQ8bP9S9iHMQxJHQAEaPHIhzv6DWa6d7QpGXyZ6zulw75bnZO0POIXB7qgdDyQnipHXnw3QmEOrhMyMXbDnELYdPNiocPXUECe7zXXwS0CHq4jsjJjR75IFFDu3GO/s6BGCNUkmYFZqVB1KtuXjXdZw73eD3XkUQoTMkXv10fcg4/JNOSiuv2hB46jvYz7LD6cGO3qAJqtrrwNf5Nrz5i6/jZHhhzoratYj2Dmq74B0DHmBO0s/7QLVeYLGw/TU3T8v+ngzVbakzTG3KQYWdWPQ2UB/V8=

Tags: Encryption Encrypt cryptography cipher ciphertext decryption decrypt Cypherpunk Crypto-anarchism Crypto anarchism

Duration : 0:6:22

Read more…

26 comments - What do you think?
Posted by admin - March 23, 2010 at 12:28 pm

Categories: Message Encryption   Tags: , , , , , , , , , , , , , , , , , , , , , , ,

Patriot Works is Digg proof thanks to caching by WP Super Cache