-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVERNIER.C
executable file
·106 lines (80 loc) · 1.54 KB
/
VERNIER.C
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Program to implement vernier encryption
Author: Bryce Lobdell
Login: lobdellb
filename: vernier.c
date: 11/5/98
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define GOOD 0
#define WRONGARGS 1
#define BADPASSWD 2
#define FALSE 0
#define TRUE 1
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
char caps(char num)
{
if (num >= 65 && num <= 90)
num+=32;
return num;
}
char alpha(char num)
{
num-=97;
return num;
}
char ascii(char num)
{
num+=97;
return num;
}
void setupkey(char *key)
{
uint keylength,loop;
keylength=strlen(key);
for (loop=0;loop<=keylength-1;loop++)
{
*(key+loop)=caps(*(key+loop));
if (!(*(key+loop) >= 97 && *(key+loop) <= 122))
{
fprintf(stderr,"Bad Password\n");
exit(BADPASSWD);
}
*(key+loop)=alpha(*(key+loop));
}
}
int main(int numargs,void *args[])
{
char *key,nextchar;
uint keylength,keylocation;
key=args[1];
keylocation=0;
if (numargs != 2 || !strcmp(key,"--help"))
{
printf("Usage: vernier KEY < INFILE > OUTFILE\n");
exit(WRONGARGS);
}
keylength=strlen(key)-1;
setupkey(key);
nextchar=fgetc(stdin);
while (nextchar != EOF)
{
nextchar=caps(nextchar);
if (nextchar <= 122 && nextchar >=97)
{
nextchar=alpha(nextchar);
nextchar+=*(key+keylocation);
nextchar=nextchar%26;
nextchar=ascii(nextchar);
keylocation++;
if (keylocation > keylength)
keylocation=0;
}
putc(nextchar,stdout);
nextchar=fgetc(stdin);
}
return 0;
}