-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path12_alternative.php
37 lines (33 loc) · 1.06 KB
/
12_alternative.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
<pre><?php
/*
columnar transposition
--> write text in columns
--> substitute ' ' with '_'
https://en.wikipedia.org/wiki/Transposition_cipher#Columnar_transposition
*/
$orig = 'idniidhsubrseognteiuignuhrzdalrd ietfetinmeablnigorcsnuatoieclei';
$step1 = str_replace(' ', '_', $orig);
echo $step1;
echo '<br />';
for($i=2; $i<strlen($step1); $i++) {
if(strlen($step1)%$i == 0) {
echo 'string is dividable by '.$i.' with 0 remainder<br />';
$tmpBreakpoint = $i-1;
$step2 = array();
for($j=0; $j<strlen($step1); $j++) {
$step2[$j%$i][] = $step1[$j];
echo $step1[$j];
if($j%$i == $tmpBreakpoint) {
echo '<br />';
}
}
echo '<br />';
for($j=0; $j<=sizeof($step2); $j++) {
for($k=sizeof($step2[$j]); $k>=0; $k--) {
echo $step2[$j][$k];
}
}
echo '<hr />';
}
}
?></pre>