-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodekey.c
More file actions
50 lines (39 loc) · 1003 Bytes
/
codekey.c
File metadata and controls
50 lines (39 loc) · 1003 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
// CYPHER PROGRAM
// Code key file for encoding and decoding for version 5.0 and up
/* Codekey.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "codekey.h"
int offset = 0;
char getNewCharacter (char input, int oneForDecode) {
int value = getValue(input);
// IF VALID LETTER
if (value < 0) {
return input;
}
offset++;
if (offset >= NUMBER_OF_CHARACTERS) {
offset = 1;
}
//printf ("offset: %d\nmake", offset);
int newValue = value - offset;
if (oneForDecode == 0) {
newValue = value + offset;
}
while (newValue > NUMBER_OF_CHARACTERS) {
newValue = newValue - NUMBER_OF_CHARACTERS;
}
while (newValue < 0) {
newValue = newValue + NUMBER_OF_CHARACTERS;
}
return CODE_KEY[newValue];
}
int getValue (char letter) {
for (int u = 0; u < NUMBER_OF_CHARACTERS; u++) {
if (letter == CODE_KEY[u]) {
return u;
}
}
return -1;
}