-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path22.php
151 lines (127 loc) · 4.71 KB
/
22.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<pre><?php
/*
playfair cipher
--> shift letters according to the rules in the predefined alphabet table
--> the letter 'j' was ommitted in the alphabet table
--> reverse the final output
https://en.wikipedia.org/wiki/Playfair_cipher
*/
$alphabet = 'abcdefghiklmnopqrstuvwxyz'; // without 'j'
$alphabetRawArray = str_split($alphabet);
$alphabet = array();
$rawCounter = 0;
for($i=0; $i<5; $i++) {
for($j=0; $j<5; $j++) {
$alphabet[$i][$j] = $alphabetRawArray[$rawCounter];
$rawCounter++;
}
}
$orig = 'opoybdpmwoqbcpqcygagpcgxbpusapdluscplchxwoisgyeasdcpopdhadfyaethis';
$wordArray = array();
for($i=0; $i<strlen($orig); $i+=2) {
$wordArray[] = $orig[$i].$orig[$i+1];
}
$output = array();
foreach($wordArray AS $combination) {
$row = '';
$column = '';
$shape = '';
$letterPosition = array();
echo strtoupper($combination).'
';
$letterPosition[] = searchInMultiArray($combination[0], $alphabet);
$letterPosition[] = searchInMultiArray($combination[1], $alphabet);
echo ' row ('.$letterPosition[0][0].' vs '.$letterPosition[1][0].'): ';
if($letterPosition[0][0] == $letterPosition[1][0]) {
$row = 'same';
echo 'same';
} elseif($letterPosition[0][0] > $letterPosition[1][0]) {
$row = 'first';
echo 'first greater';
} else {
$row = 'last';
echo 'last greater';
}
echo '
';
echo ' column ('.$letterPosition[0][1].' vs '.$letterPosition[1][1].'): ';
if($letterPosition[0][1] == $letterPosition[1][1]) {
$column = 'same';
echo 'same';
} elseif($letterPosition[0][1] > $letterPosition[1][1]) {
$column = 'first';
echo 'first greater';
} else {
$column = 'last';
echo 'last greater';
}
echo '
';
if($row == 'same' && $column == 'same') {
$output[] = 1;
$output[] = $alphabet[$letterPosition[0][0]][$letterPosition[0][1]];
$output[] = $alphabet[$letterPosition[1][0]][$letterPosition[1][1]];
} elseif($row == 'same' && $column == 'first') {
$output[] = $alphabet[$letterPosition[0][0]][targetValue($letterPosition[0][1])];
$output[] = $alphabet[$letterPosition[1][0]][targetValue($letterPosition[1][1])];
} elseif($row == 'same' && $column == 'last') {
$output[] = $alphabet[$letterPosition[0][0]][targetValue($letterPosition[0][1])];
$output[] = $alphabet[$letterPosition[1][0]][targetValue($letterPosition[1][1])];
} elseif($row == 'first' && $column == 'same') {
$output[] = $alphabet[targetValue($letterPosition[0][0])][$letterPosition[0][1]];
$output[] = $alphabet[targetValue($letterPosition[1][0])][$letterPosition[1][1]];
} elseif($row == 'last' && $column == 'same') {
$output[] = $alphabet[targetValue($letterPosition[0][0])][$letterPosition[0][1]];
$output[] = $alphabet[targetValue($letterPosition[1][0])][$letterPosition[1][1]];
} elseif(
($row == 'first' && $column == 'first') ||
($row == 'first' && $column == 'last') ||
($row == 'last' && $column == 'first') ||
($row == 'last' && $column == 'last')
) {
// rectangle
$output[] = $alphabet[$letterPosition[0][0]][$letterPosition[1][1]];
$output[] = $alphabet[$letterPosition[1][0]][$letterPosition[0][1]];
} else {
$output[] = 7;
$output[] = '.';
$output[] = '.';
}
echo '
';
}
$outputTMP = implode(' ', $output);
echo $outputTMP.'
'.strrev($outputTMP);
function searchInMultiArray($character, $array) {
foreach($array as $key1 => $val1) {
foreach($val1 as $key2 => $val2) {
if($val2 === $character) {
return array($key1, $key2);
}
}
}
return null;
}
function targetValue($valueIn, $method = 'substract') {
if($method == 'add') {
$valueOut = $valueIn+1;
} elseif($method == 'substract') {
$valueOut = $valueIn-1;
} else {
$valueOut = $valueIn;
}
if($valueOut < 0) {
$valueOut = 4;
} elseif($valueOut > 4) {
$valueOut = 0;
}
return $valueOut;
}
?>
<hr /><hr />
solution:
this device i connected with my scanner to alert me when fbi was near my location
answer to the solution:
DDI - "digital-data interpreter"
</pre>