-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumEncoder.c
More file actions
106 lines (95 loc) · 1.74 KB
/
Copy pathPrimeNumEncoder.c
File metadata and controls
106 lines (95 loc) · 1.74 KB
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
/*
><><><><><><><><><><><><><><><><><><><><><><><><><><><
>
>
> Filename : PrimeNumEncoder.c
> Explanation : Cipher Encoder with Prime Numbers
>
> Compiler : TDM-GCC 4.9.2
>
> Developer : Emre Berber
> Other : emreberber.com
>
><><><><><><><><><><><><><><><><><><><><><><><><><><><
*/
#include <stdio.h>
#include <stdlib.h>
int PrimeControl(int num)
{
int i , counter=0 ;
for(i=1 ; i<num ; i++)
{
if(num%i==0 && num>2)
{
counter ++ ;
}
}
if(counter==1)
{
return 1 ;
}
else
{
return 0 ;
}
}
void PrimeNumber(char Array[] , int num1 , int num2)
{
int key , j=0 , i;
for(i=0 ; Array[i]!='\0' ; i++)
{
if(j%2==0 && Array[i]!=32)
{
key = num1 ;
}
else if(j%2==1 && Array[i]!=32)
{
key = num2 ;
}
else if(Array[i]==32)
{
j++ ;
}
if(Array[i]<91 && Array[i]!=32)
{
if(Array[i]-64 + key != 26)
{
Array[i]=64+(Array[i]-64 + key)%26 ;
}
}
else if(Array[i]>96)
{
if(Array[i]-96 + key != 26)
{
Array[i]=96+(Array[i]-96 + key)%26 ;
}
}
j++ ;
}
}
int main()
{
char Array[40];
int num1, num2 ,i ;
printf("Prime Number Encoder \n\n");
printf("Press String : "); gets(Array);
printf("1st Prime Number : "); scanf("%d",&num1);
printf("2nd Prime Number : "); scanf("%d",&num2);
if (PrimeControl(num1) + PrimeControl(num2)==2)
{
PrimeNumber(Array,num1,num2) ;
printf("Cipher Text : ");
for(i=0 ; Array[i]!='\0'; i++)
{
printf("%c",Array[i]);
}
}
else
{
printf("\nError Message ! \n");
printf("First and second number must be prime");
}
printf("\n\n");
system("pause");
return 0;
}