Q&A: C++ Multidimensional array problem with Playfair cipher?
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!
Categories: Internet Access Tags: Breakfast, Complimentary, Golf, Mornings, Resort, right, start, Tucson, Wyndham
Problem trying to “repair” my computer?
Question by mrg061990: Problem trying to “repair” my computer?
When ever I get done using my CPU for a night, I turn it back on in the morning and it freezes when booting up on the Windows XP Logo. I can not figure out the problem so since I have a Dell I use the CTRL + F11 function like I have before once to restore my CPU but once I get the the restore part my keyboard just won’t work ( Bluetooth) but it has before it works when I press CTRL + F11 though. I even plugged in a USB keyboard so I could try that Please HELP ME!!!!!!!!!!!
By the way Guy below I can get into regulare mode but when I first boot up it freezes but when I turn it on again it works fine but I have tried system restore doesnt work.I try to restore my cpu CTRL+F11 but once it gets to were it says restore or re boot It wont let me choose with my Keyboard it like it doesnt work
Best answer:
Answer by sashawhitefur
It sounds like you have a corrupt install of the operating system. If you cannot open in normal mode, try loading Safe Mode, then run System Restore.
To get to Safe Mode, when your computer is starting, continually press F8.
Add your own answer in the comments!
Categories: computer repair Tags: computer, Problem, repair, trying
LG Incite : Wi-Fi connection
For more info go to :
www.LG-Incite.com
please read!!! use ” INTERNET EXPLORER ” don’t use any of your network programs like ” media net ” etc. cuz they might charge you..
this video is for those people whos having a problem ussing their LG incite wi-fi feature..
you need to ” DISABLE ” your proxy cos even if your phone is already connected, the internet is not gonna work unless you DISABLE your PROXY..
-START
-PROGRAMS
-TOOLS
-PROXY MANAGER
-DISABLE PROXY
-PRESS OK
enjoy you’re free internet! IT’S FREE! =]
Duration : 0:1:37
Get “WIFI” Anywhere You Have Cell-Phone Service! (Mac, PC)
http://jpfilms.info
Today I will show you a relatively simple process called tethering. It allows you to take a cell phone that has Internet access, and use it on a computer. Example: you’re driving, you get stranded, And your phone’s screen is broken so you really cant text for help ( 911 is also not available) of course this is all just a scenario I’ve made up. You could also be in school without WiFi although you have your phone and a laptop. You simply want to be able to take your phone’s Internet and use it on your laptop. That’s what I’m going to show you how to do… This process is known as “tethering”, as long as you have free cell phone Internet, your bill will not increase in cost. If your plan does not contain free Internet, your bill will spike. So be careful. I hope you all enjoy this tutorial, have a good day.
Jonathan
Duration : 0:6:54
Categories: Internet Access Tags: air, and, Apple, application, Art, Arts, AWESOME, Beauty, Bittorrent, Blower, Booth, Brake, broadband, Broadband Companies, Broadband Coverage, Caddy, Capture, computer, cool, Crafts, dance, Death, Drink, Electricity, Explosion, Figure, Films, finance, fix, Food, free, Fun, funny, Grass, Hand, help, home, hot, imac, Imovie, in, Install, Interesting, Internet Access, Internet Access Companies, Internet Coverage, Internet Providers, Invention, Inventorkid13, Iphoto, Ipod, IT, Jobs, Jonathan, Jonathanfilms, Jpfilms, Kill, Log, Loki, macbook, me, MP4, Music, Neat, Need, Now, Odd, Patriot Works, pc, Perfect, Photo, Photobooth, Pictures, Pivot, Please, Post, Problem, project, Pyro, quality, Screen, secret, settings, sexy, Webcast Access, wifi, WiFi locations

