-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.c
92 lines (87 loc) · 1.83 KB
/
hash.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
#include <stdio.h>
//In The Name Of God who is developing our lifes Algorithm
//Mohammadreza Sharifi
#include <string.h>
#include <time.h>
int charToInt(char c)
{
int num = 0;
num = c - '0';
return num;
}////
/////////////////////////////////////////////////////////////
void reverse(char str[])
{
int n = strlen(str);
for (int i = 0; i < n / 2; i++)
{
char ch = str[i];
str[i] = str[n - i - 1];
str[n - i - 1] = ch;
}
}
////////////////////////////////////////////////////////
char *hash(int a)
{
int s = (clock() % 7) + 3;
char origin[50], c[50], d[50], fina[50];
int o, p, lota;
o = (s * a * s);
sprintf(origin, "%d", o);
lota = strlen(origin);
strcpy(d, origin);
strcat(origin, d);
reverse(origin);
int k;
char word;
char fonat[50];
k = strlen(origin);
for (int i = 0; i < k; i++)
{
p = (rand() % 27) + 1;
p += 55;
word = p;
fonat[i] = word;
}
for (int i = 0; i < k; i++)
{
fina[2 * i] = fonat[i];
p=charToInt(origin[i]);
fina[(2 * i) + 1] =65+p;
}
strcpy(d, fina);
int t;
sprintf(c, "%d", s);
sprintf(origin, "%d", lota);
strcat(c, origin);
strcat(c, fina);
char *sut;
sut = c;
return sut;
}
///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
int dhash(char a[50])
{
int j = 0;
int b;
b = 0;
int k = charToInt(a[1]);
int s = charToInt(a[0]);
char w;
int sal = 3;
char final[10];
for (int i = 0; i < k; i++)
{
w = ((a[sal + (2 * i)])%64)+47;
final[k - i - 1] = w;
}
b = 0;
for (int i = 0; i < k; i++)
{
j = charToInt(final[i]);
b = (b * 10) + j;
}
b /= s * s;
return b;
}