-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt2.php
60 lines (50 loc) · 1.81 KB
/
encrypt2.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
<?php
define("Hash_Key", "fa3365ac3758864fffade2be294e4267311d1a8414005bb839a17bd298a8bd56");
define("codOK", "p0r5c43");
function safeEncrypt(string $message, string $key){
if (mb_strlen($key, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
throw new RangeException('Key is not he correct size (must be 32 bytes)');
}
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$cipher = base64_encode(
$nonce.
sodium_crypto_secretbox(
$message,
$nonce,
$key
)
);
sodium_memzero($message);
sodium_memzero($key);
return $cipher;
}
function safeDecrypt(string $encrypted, string $key){
$decoded = base64_decode($encrypted);
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
$plain = sodium_crypto_secretbox_open(
$ciphertext,
$nonce,
$key
);
if (!is_string($plain)) {
throw new Exception('Invalid MAC');
}
sodium_memzero($ciphertext);
sodium_memzero($key);
return $plain;
}
//Previously generated codes: 474 - 547
$format="0000";
for($i=1;$i<=547;$i++){
$ciphertext=$format;
if(strlen((string)$i)==1)$ciphertext=safeEncrypt("p0r5c43" . "000" . (string)$i, hex2bin(Hash_Key));
if(strlen((string)$i)==2)$ciphertext=safeEncrypt("p0r5c43" . "00" . (string)$i, hex2bin(Hash_Key));
if(strlen((string)$i)==3)$ciphertext=safeEncrypt("p0r5c43" . "0" . (string)$i, hex2bin(Hash_Key));
if(strlen((string)$i)==4)$ciphertext=safeEncrypt("p0r5c43" . (string)$i, hex2bin(Hash_Key));
//$ciphertext = safeEncrypt("p0r5c43" . "0" . (string)$i, hex2bin(Hash_Key));
echo $ciphertext;
echo "<br>";
//echo substr_replace(safeDecrypt($ciphertext, hex2bin(Hash_Key)),'',0,strlen(codOK));
}
?>