Commit cc74b947 authored by xingqiao's avatar xingqiao
Browse files

helloworld basic code files

parent 4ddf4daa
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc != 4) {
fprintf(stderr, "usage: %s <encrypt|decrypt> <password> <message>\n", argv[0]);
exit(1);
}
if (strcmp(, "encrypt") == ) {
} else if (strcmp(, "decrypt") == ) {
char *c = argv[2], *m = argv[3];
int pass[100], plen = 0;
for (int i = 0; i < strlen(c); i++) {
if (c[i] <= 'z' && c[i] >= 'a') {
pass[plen++] = c[i] - 'a';
}
if (c[i] <= 'Z' && c[i] >= 'A') {
pass[plen++] = c[i] - 'A';
}
}
if (strcmp(argv[1], "encrypt") == 0) {
if (plen == 0) {
pass;
} else {
int k = 0;
for (int i = 0; i < strlen(m); i++) {
if (m[i] <= 'z' && m[i] >= 'a') {
// m[i] += pass[k%plen];
// k++;
if(m[i] + pass[k%plen] > 'z') {
m[i] = 'a' + m[i] - 'z' - 1 + pass[k%plen];
} else {
m[i] += pass[k%plen];
}
k++;
} else if (m[i] <= 'Z' && m[i] >= 'A') {
// m[i] += pass[k%plen];
// k++;
if(m[i] + pass[k%plen] > 'Z') {
m[i] = 'A' + m[i] - 'Z' - 1 + pass[k%plen];
} else {
m[i] += pass[k%plen];
}
k++;
} else {
pass;
}
}
}
printf("%s\n", m);
} else if (strcmp(argv[1], "decrypt") == 0) {
if (plen == 0) {
pass;
}
else {
int k = 0;
for (int i = 0; i < strlen(m); i++) {
if (m[i] <= 'z' && m[i] >= 'a') {
m[i] -= pass[k%plen];
k++;
if(m[i] < 'a') {
m[i] = 'z' -('a' - m[i]) + 1;
}
} else if (m[i] <= 'Z' && m[i] >= 'A') {
m[i] -= pass[k%plen];
k++;
if(m[i] < 'A') {
m[i] = 'Z' - ('A' - m[i]) + 1;
}
} else {
pass;
}
}
}
printf("%s\n", m);
} else {
fprintf(stderr, "expected command encrypt or decrypt. got '%s'\n", argv[1]);
return 1;
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment