· 7 years ago · Jun 25, 2018, 01:52 AM
1// ACipher.cpp : Defines the entry point for the console application.
2//
3
4#include "stdafx.h"
5#include <string>
6#include <iostream>
7#pragma warning(disable:4996)
8using namespace std;
9
10int main()
11{
12
13 char sec[100];
14 char phrase[100];
15 char encoded[100];
16
17
18 printf("%s\n", "Enter secretkey");
19 scanf("%s", sec);
20
21 printf("%s\n", "Enter phrase to be encoded");
22 scanf("%s", phrase);
23
24 int phraselen=0;
25 int seclen = 0;
26
27 int j = 0;
28 while (phrase[j] != '\0') {
29 phraselen++;
30 j++;
31 }
32
33 j = 0;
34 while(sec[j] != '\0') {
35 seclen++;
36 j++;
37 }
38 j = 0;
39 int k = 0;
40
41 if (phraselen > seclen) {
42 for (int m = seclen; m < phraselen; m++) {
43 sec[seclen + j] = sec[k];
44 j++;
45 k++;
46 }
47
48 seclen = phraselen;
49 sec[seclen] = '\0';
50 }
51
52
53
54 int temp;
55 temp = phrase[0] + (sec[0]-'a')-26;
56
57
58 int i;
59
60 for (i = 0; i < phraselen; i++) {
61 temp = phrase[i] + (sec[i]-'a');
62
63 if (temp > 122) {
64 temp = temp - 26;
65 }
66
67 encoded[i] = temp;
68
69
70}
71 encoded[i] = '\0';
72
73 printf("%s\n", encoded);
74
75
76 return 0;
77}