Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help to fix this program (find trigrams)

Status
Not open for further replies.

eziama

Newbie level 1
Newbie level 1
Joined
Oct 3, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
46

Code C - [expand]
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[]= “PYHLKFHPDQXFYWMEEGTWYCSEVVDDMIUHHLHZXWCSECYVNBSVUBNRWRAKGYXRNCSMJSQHSJIJCBCGOEQKSFIEGLSRLZPUXMYIGUNGRXVCRYCZUVNUQRPMOCSGNSGYZVACTNSZUCMCHZRZDYHVFUTGPKAKHRLRNOTELZHMNSTVQDKCSENMJLINJCVDEKCZKWIRUMHRMJVCOMMJQBRMQVQBDZCDKGSYOVACTUSLNRMRNFMSZZSLVWSASDGCMJIKUVZTIKGOVCZVICSYPCUCQRWFHGDAVVVGSMVZGGHLXYCHBSTSQOQBRFNOVPIEESSFEKUHGCTFKGNLGLRPNYVUVVDZMXEIOZSRTRSFEKUFHELKYSGYHRXSQWGYGSQWXVCOMBEJUWRRIUEMMRLZCHNUEJJIOYJKGFVYVUUKDFEULIRRTLVOVYCKJSKYWKVSZQTFQBVFIECYMMGBEOLCEKVVDBSFTHGCGFWBSCRRPQDQSWEMMRLZCOMBRZDGVCVVUICBIENMOCXIKTHCHZPHNYWKG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MEIANPIKQRNLMSUBNYPCTWFFXKJSMUITCBKMGBWDZLHXQWGYHJGSMJENTSMAIZPETGXVCRHDJVTSMRPZIVSRLRVOERIIPCNLGFODZPIUVCIMLEJSVYWRPORRSLPRHLKCARHDJZEIKRTVTGNLXFISSRSBPCVFINCGSFIFRDNQMKGCEFMJDFNRLVTWMYPDQGSCZVTMQCWGGQSZIZPUTLYJWOKJCJJMZLHIGGDPZVFMDRLVJOCYGVTHZGRTJOQKSWOOMLIICBCGJRPQHCHKJOSGJFPSQCECNMJLINJWLUICNCMCGFWZCFEMGOCCIGCTECGKKCMDSIJWLGLRFOKUEPUTZLGZGRSFEKJWRKEEPSQRSTABSFMRYORPEKJSQASEUHQYMEGRZLHKJOSQLVQBGCVJKRDUEJKBBJMEGR";
    
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

 
Last edited by a moderator:

Hi,

I find it rather impolite to post a piece of code and expect others to solve your problem...Without "Hello", without comments, without error description, without any assitance.

Klaus
 

It also shows a lack of respect for others time, and the code itself proves that the OP does not know how to even debug something, e.g. there are no debug statements anywhere to even attempt to diagnose a problem.

They probably downloaded this from somewhere compiled it and it didn't produce the answers they wanted or thought they should get.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top