-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_2.cpp
More file actions
82 lines (73 loc) · 1.31 KB
/
2_2.cpp
File metadata and controls
82 lines (73 loc) · 1.31 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
#include <iostream>
#include <string>
#include <cstddef>
using namespace std;
size_t checkValid(string name)
{
size_t found = string::npos;
// check length
if (name.size() < 4)
{
cout << "Firstname have to be min. 4 chars" << endl;
return found;
}
// check format
char check[] = { 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U' };
for (size_t i = 0; i < 10; i++)
{
found = name.find_first_of(check[i]);
if (found != string::npos)
{
return i;
}
}
cout << "Firstname is not a real firstname " << endl
<< "Choose a right one" << endl;
return found;
}
void generateKey(string firstname)
{
size_t found = checkValid(firstname);
if (found == string::npos)
return;
int option = static_cast<int>(found);
unsigned int result = firstname.size();
switch (option)
{
case 0:
case 1:
result = result * 74545 + 6708960;
break;
case 2:
case 3:
result = result * 18303 + 237952;
break;
case 4:
case 5:
result = result * 95683 + 2966204;
break;
case 6:
case 7:
result = result * 95683 + 2966204;
break;
case 8:
case 9:
result = result * 23454 + 2087495;
break;
}
cout << "SerialNr: " << result << endl;
return;
}
int main()
{
while (1)
{
string firstname;
cout << "Firstname: ";
cin >> firstname;
generateKey(firstname);
cout << endl;
}
system("pause");
return 0;
}