Voor een speciale crypt functie die onder andere gebruik maakt van Extended DES encryptie, moet ik het aantal rondes (irritations) opgeven dat de library uitvoert. Blijkbaar is Extended DES vrij ingewikkeld, want het maakt gebruik van de volgende conversietabel:
. = 0
/ = 1
0 = 2
1 = 3
2 = 4
(t/m 9 = 11)
A = 12
B = 13
(t/m Z = 37)
a = 38
b = 39
(t/m z = 63)
Het aantal ronden wordt uitgedrukt in een string met de bovenstaande karakters (voorbeeld: /.Aa). Om te berekenen welke tekens je moet gebruiken heb ik het volgende schematje:
k1 * 64 ^ 0 = A
k2 * 64 ^ 1 = B
k3 * 64 ^ 2 = C
k4 * 64 ^ 3 = D
Hier staat A+B+C+D voor het aantal ronden, en k1 t/m k4 voor de vier karakters die de string bevat.
Bron die ik heb gebruikt: http://arstechnica.com/civis/viewtopic.php?f=20&t=1125143 (tweede post)
Voor de duidelijkheid: het is de bedoeling dat ik van het aantal rondes naar de string ga. Hiervoor heb ik de volgende code gemaakt:
Het script zelf geeft echter notices, en de string klopt nog niet. Momenteel lukt het me niet om formules hiervoor te verzinnen, dus ik vraag jullie om hulp. Alvast bedankt!
. = 0
/ = 1
0 = 2
1 = 3
2 = 4
(t/m 9 = 11)
A = 12
B = 13
(t/m Z = 37)
a = 38
b = 39
(t/m z = 63)
Het aantal ronden wordt uitgedrukt in een string met de bovenstaande karakters (voorbeeld: /.Aa). Om te berekenen welke tekens je moet gebruiken heb ik het volgende schematje:
k1 * 64 ^ 0 = A
k2 * 64 ^ 1 = B
k3 * 64 ^ 2 = C
k4 * 64 ^ 3 = D
Hier staat A+B+C+D voor het aantal ronden, en k1 t/m k4 voor de vier karakters die de string bevat.
Bron die ik heb gebruikt: http://arstechnica.com/civis/viewtopic.php?f=20&t=1125143 (tweede post)
Voor de duidelijkheid: het is de bedoeling dat ik van het aantal rondes naar de string ga. Hiervoor heb ik de volgende code gemaakt:
PHP:
<?php
$rounds = 5000;
// Generating conversion table for Extended DES irritation conversion
$charset = './';
$charset .= '0123456789';
$charset .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charset .= 'abcdefghijklmnopqrstuvwxyz';
$charextd = array();
for($i = 0; $i < strlen($charset); $i++) {
$charextd[] = $charset[$i];
}
// Generating iritation string with var $round
if($rounds < 64) {
$irritation = $charextd[$rounds];
$irritation .= '.';
$irritation .= '.';
$irritation .= '.';
} elseif($rounds < 4096) {
$irritation = $charextd[$rounds - (floor($rounds / 64) * 64)];
$irritation .= $charextd[floor($rounds / 64)];
$irritation .= '.';
$irritation .= '.';
} elseif($rounds < 262144) {
$irritation = $charextd[$rounds - (floor($rounds / 64) * 64)];
$irritation .= $charextd[$rounds - (floor($rounds / 4096) * 4096)];
$irritation .= $charextd[floor($rounds / 64)];
$irritation .= '.';
} elseif($rounds < 16777216) {
$irritation = $charextd[$rounds - (floor($rounds / 64) * 64)];
$irritation .= $charextd[$rounds - (floor($rounds / 4096) * 64)];
$irritation .= $charextd[$rounds - (floor($rounds / 262144) * 64)];
$irritation .= $charextd[floor($rounds / 64)];
} else {
$irritation = 'z';
$irritation .= 'z';
$irritation .= 'z';
$irritation .= 'z';
}
echo $irritation;
?>
Het script zelf geeft echter notices, en de string klopt nog niet. Momenteel lukt het me niet om formules hiervoor te verzinnen, dus ik vraag jullie om hulp. Alvast bedankt!