What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Description
"The Alphabet Cipher", published by Lewis Carroll in 1868, describes a Vigenère cipher (thanks /u/Yadkee for the clarification) for passing secret messages. The cipher involves alphabet substitution using a shared keyword. Using the alphabet cipher to tranmit messages follows this procedure:
You must make a substitution chart like this, where each row of the alphabet is rotated by one as each letter goes down the chart. All test cases will utilize this same substitution chart.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A abcdefghijklmnopqrstuvwxyz
B bcdefghijklmnopqrstuvwxyza
C cdefghijklmnopqrstuvwxyzab
D defghijklmnopqrstuvwxyzabc
E efghijklmnopqrstuvwxyzabcd
F fghijklmnopqrstuvwxyzabcde
G ghijklmnopqrstuvwxyzabcdef
H hijklmnopqrstuvwxyzabcdefg
I ijklmnopqrstuvwxyzabcdefgh
J jklmnopqrstuvwxyzabcdefghi
K klmnopqrstuvwxyzabcdefghij
L lmnopqrstuvwxyzabcdefghijk
M mnopqrstuvwxyzabcdefghijkl
N nopqrstuvwxyzabcdefghijklm
O opqrstuvwxyzabcdefghijklmn
P pqrstuvwxyzabcdefghijklmno
Q qrstuvwxyzabcdefghijklmnop
R rstuvwxyzabcdefghijklmnopq
S stuvwxyzabcdefghijklmnopqr
T tuvwxyzabcdefghijklmnopqrs
U uvwxyzabcdefghijklmnopqrst
V vwxyzabcdefghijklmnopqrstu
W wxyzabcdefghijklmnopqrstuv
X xyzabcdefghijklmnopqrstuvw
Y yzabcdefghijklmnopqrstuvwx
Z zabcdefghijklmnopqrstuvwxy
Both people exchanging messages must agree on the secret keyword. To be effective, this keyword should not be written down anywhere, but memorized.
To encode the message, first write it down.
thepackagehasbeendelivered
Then, write the keyword, (for example, snitch), repeated as many times as necessary.
snitchsnitchsnitchsnitchsn
thepackagehasbeendelivered
Now you can look up the column S in the table and follow it down until it meets the T row. The value at the intersection is the letter L. All the letters would be thus encoded.
snitchsnitchsnitchsnitchsn
thepackagehasbeendelivered
lumicjcnoxjhkomxpkwyqogywq
The encoded message is now lumicjcnoxjhkomxpkwyqogywq
To decode, the other person would use the secret keyword and the table to look up the letters in reverse.
Input Description
Each input will consist of two strings, separate by a space. The first word will be the secret word, and the second will be the message to encrypt.
snitch thepackagehasbeendelivered
Output Description
Your program should print out the encrypted message.
lumicjcnoxjhkomxpkwyqogywq
Challenge Inputs
bond theredfoxtrotsquietlyatmidnight
train murderontheorientexpress
garden themolessnuckintothegardenlastnight
Challenge Outputs
uvrufrsryherugdxjsgozogpjralhvg
flrlrkfnbuxfrqrgkefckvsa
zhvpsyksjqypqiewsgnexdvqkncdwgtixkx
Solution
in C
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int
main(void)
{
char line[1024];
while (fgets(line, sizeof(line), stdin)) {
char *key = line;
char *plain = strchr(line, ' ') + 1;
size_t keylen = plain - key - 1;
for (char *p = plain; isalpha(*p); p++) {
size_t i = p - plain;
int cipher = (*p - 'a' + key[i % keylen] - 'a') % 26;
putchar('a' + cipher);
}
putchar('\n');
}
}
"The Alphabet Cipher", published by Lewis Carroll in 1868, describes a Vigenère cipher (thanks /u/Yadkee for the clarification) for passing secret messages. The cipher involves alphabet substitution using a shared keyword. Using the alphabet cipher to tranmit messages follows this procedure:
You must make a substitution chart like this, where each row of the alphabet is rotated by one as each letter goes down the chart. All test cases will utilize this same substitution chart.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A abcdefghijklmnopqrstuvwxyz
B bcdefghijklmnopqrstuvwxyza
C cdefghijklmnopqrstuvwxyzab
D defghijklmnopqrstuvwxyzabc
E efghijklmnopqrstuvwxyzabcd
F fghijklmnopqrstuvwxyzabcde
G ghijklmnopqrstuvwxyzabcdef
H hijklmnopqrstuvwxyzabcdefg
I ijklmnopqrstuvwxyzabcdefgh
J jklmnopqrstuvwxyzabcdefghi
K klmnopqrstuvwxyzabcdefghij
L lmnopqrstuvwxyzabcdefghijk
M mnopqrstuvwxyzabcdefghijkl
N nopqrstuvwxyzabcdefghijklm
O opqrstuvwxyzabcdefghijklmn
P pqrstuvwxyzabcdefghijklmno
Q qrstuvwxyzabcdefghijklmnop
R rstuvwxyzabcdefghijklmnopq
S stuvwxyzabcdefghijklmnopqr
T tuvwxyzabcdefghijklmnopqrs
U uvwxyzabcdefghijklmnopqrst
V vwxyzabcdefghijklmnopqrstu
W wxyzabcdefghijklmnopqrstuv
X xyzabcdefghijklmnopqrstuvw
Y yzabcdefghijklmnopqrstuvwx
Z zabcdefghijklmnopqrstuvwxy
Both people exchanging messages must agree on the secret keyword. To be effective, this keyword should not be written down anywhere, but memorized.
To encode the message, first write it down.
thepackagehasbeendelivered
Then, write the keyword, (for example, snitch), repeated as many times as necessary.
snitchsnitchsnitchsnitchsn
thepackagehasbeendelivered
Now you can look up the column S in the table and follow it down until it meets the T row. The value at the intersection is the letter L. All the letters would be thus encoded.
snitchsnitchsnitchsnitchsn
thepackagehasbeendelivered
lumicjcnoxjhkomxpkwyqogywq
The encoded message is now lumicjcnoxjhkomxpkwyqogywq
To decode, the other person would use the secret keyword and the table to look up the letters in reverse.
Input Description
Each input will consist of two strings, separate by a space. The first word will be the secret word, and the second will be the message to encrypt.
snitch thepackagehasbeendelivered
Output Description
Your program should print out the encrypted message.
lumicjcnoxjhkomxpkwyqogywq
Challenge Inputs
bond theredfoxtrotsquietlyatmidnight
train murderontheorientexpress
garden themolessnuckintothegardenlastnight
Challenge Outputs
uvrufrsryherugdxjsgozogpjralhvg
flrlrkfnbuxfrqrgkefckvsa
zhvpsyksjqypqiewsgnexdvqkncdwgtixkx
Solution
in C
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int
main(void)
{
char line[1024];
while (fgets(line, sizeof(line), stdin)) {
char *key = line;
char *plain = strchr(line, ' ') + 1;
size_t keylen = plain - key - 1;
for (char *p = plain; isalpha(*p); p++) {
size_t i = p - plain;
int cipher = (*p - 'a' + key[i % keylen] - 'a') % 26;
putchar('a' + cipher);
}
putchar('\n');
}
}
Comments
Post a Comment