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
| % FINDING TRIGRAMS AND THEIR OCCURENCES#START
#include <stdio.h>
#include <string.h>
void main(void)
{
char mainstring[]= “PYHLKFHPDQXFYWMEEGTWYCSEVVDDMIUHHLHZXWCSECYVNBSVUBNRWRAKGYXRNCSMJSQHSJIJCBCGOEQKSFIEGLSRLZPUXMYIGUNGRXVCRYCZUVNUQRPMOCSGNSGYZVACTNSZUCMCHZRZDYHVFUTGPKAKHRLRNOTELZHMNSTVQDKCSENMJLINJCVDEKCZKWIRUMHRMJVCOMMJQBRMQVQBDZCDKGSYOVACTUSLNRMRNFMSZZSLVWSASDGCMJIKUVZTIKGOVCZVICSYPCUCQRWFHGDAVVVGSMVZGGHLXYCHBSTSQOQBRFNOVPIEESSFEKUHGCTFKGNLGLRPNYVUVVDZMXEIOZSRTRSFEKUFHELKYSGYHRXSQWGYGSQWXVCOMBEJUWRRIUEMMRLZCHNUEJJIOYJKGFVYVUUKDFEULIRRTLVOVYCKJSKYWKVSZQTFQBVFIECYMMGBEOLCEKVVDBSFTHGCGFWBSCRRPQDQSWEMMRLZCOMBRZDGVCVVUICBIENMOCXIKTHCHZPHNYWKGFMYRUHCQZMUFWMEIORFDQWZQBBMQVKBRYMUEMMRLZCWMYWYCFONVFHSRQMFPOKRSEGOXMYEIOMBVRVVDPWTCFDBPFQYHLKEWFRCEGRSZPIUYWSFESQHSJINJWBFWYGDQMJWGFDBXFPWAQAYQKZTIUJSQRSNCFCQGPPHGGENKHGRLVUCLCAYCHDLMXOOSGGRNFDKEIMWLLSKTSZJPPJSQCXFFOXACEVVHYXFQYSFISQHSJIRPRDVEDKBDBMKYWSFXYGG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GJRPQHCHKJOSGJFPSQCECNMJLINJWLUICNCMCGFWZCFEMGOCCIGCTECGKKCMDSIJWLGLRFOKUEPUTZLGZGRSFEKJWRKEEPSQRSTABSFMRYORPEKJSQASEUHQYMEGRZLHKJOSQLVQBGCVJKRDUEJKBBJMEGR";
char substring[20], *ret;
int i=0;
int x,y,z;
x=y=z=0;
clrscr();
puts("enter the sub stirng to find");
fgets(substring, sizeof(substring), stdin);
substring[strlen(substring)-1]='\0';
ret=strstr(mainstring,substring);
if(strcmp((ret=strstr(mainstring,substring)),substring))
{
printf("Substring is present.\n");
}
while (mainstring[x]!='\0')
{
if(mainstring[x] == substring[y] && mainstring[x+1] == substring[y+1])
{
z=z++;
}
x++;
}
printf("Numer of occurance is: %d \n", z);
getch();
}
% FINDING TRIGRAMS AND THEIR OCCURENCES#END
%DECRYPTING THE CIPHERTEXT#START
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void upper_case(char *src)
{
while (*src != '\0')
{ if(islower(*src)) *src &= ~0x20;
src++;
}
}
char* decipher(const char *src, char *key, int is_encode)
{
int i, klen, slen;
char *dest;
dest = strdup(src);
upper_case(dest);
upper_case(key);
/* strip out non-letters */
for (i = 0, slen = 0; dest[slen] != '\0'; slen++)
if (isupper(dest[slen]))
dest[i++] = dest[slen];
dest[slen = i] = '\0'; /* null pad it, make it safe to use */
klen = strlen(key);
for (i = 0; i < slen; i++) {
if (!isupper(dest[i])) continue;
dest[i] = 'A' + (is_encode
? dest[i] - 'A' + key[i % klen] - 'A'
: dest[i] - key[i % klen] + 26) % 26;
}
return dest;
}
int main()
{
const char *str =
"XPOZTRACLKWWIVGJCYLWTWUYTPQILMLIZZAITKAMLMJVKQWAZXKWUUYSZYVFIBOTXAQZOHYBOUMIZXBIXQTNBXBNLRAMXLEIIXUBROZVWVICAAILUYFSCYLPIVZVGCICUBROGUWVCHIBROOALIGKZYSZOAPEAMLMXQTNOIZEZEIMVFTRLZOXCLXLPETRTTRVKYHJBNPGKAKCXVGZOBROZOTXJKNBRACPMLITTPLGCPMLITTLEQJHEMKKDACVUALEQJAAIUGYVLPGYXETOJXAIYZBPMTAMLMJVKQWAZXLIJJESAKKBXAKFXWJEAAMAZPFIITKPEAMVBROUMYMVZVTHWFLUYBUUUIQTNIMVIOXHJEAAIPGAMIZOAPSSKBIEOGPGAQZOTPQZAEIANYBISGUWAMTAHRBNHMFMMPGWEOAAEVSZNGPGZFSCYLMVIVZTRLZOXQWUUTRLSLFSZEHGHUAJARMYZRSCQUHAGUBLEGZOBROYHKIUAJASNGTNGPTLLWLOKRSCKCXVAKLLYKNHMLQTNTWIJYTAQTNHJISBVLVKZLVMGSECVUDRSCGZDQMYHBHIRPVIDKYRQCIOVSVLBLILOKHRBZOBRSZOXRGUBLLWASWRBZHEOAGPWXPKOTXBKY";
const char *dec;
char key[] = "EIGHT";
clrscr();
printf("ciphertext: %s\n", str);
printf("keyword: %s\n", key);
dec =decipher(str,key,0);
printf("plaintext: %s\n", dec);
getch();
}
%DECRYPTING THE CIPHERTEXT #END
%PROGRAM ENDS |