-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject5_decrypt.c
More file actions
38 lines (29 loc) · 1.14 KB
/
project5_decrypt.c
File metadata and controls
38 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Anisha Hossain Megha (U43189731)
// Task 1 - program to decrypt a message that is encrypted.
// In the encrypted message the first character is written once, second character twice, third character three times, .., and mth character m times.
// program decrypts message so that each character is written once.
#include <stdio.h>
void decrypt(char *input, char *output){
char *p = input; // pointer to (first char of) array input
char *o = output; // pointer to output
int j = 0;
int i = 2;
*o = *p; // setting first char of output to first char of input
// loop for decryption and adding decrypted characters to output
while(*(p + j + i) != '\0'){
*(o + 1) = *(p + j + i);
o++;
j = j + i;
i++;
}
*(o + 1) = '\0'; // adding null character at end
}
int main(){
char input[1000]; // array for inout by user
printf("Enter message: ");
scanf("%s", input); // storing input to array
char output[1000]; // array for storing decrypted message
decrypt(input, output); // call to function
printf("Output: %s", output);
return 0;
}