<?php
function decrypt_and_get_counter() {
$iv = str_repeat("\x00", 16); // Initialisierungsvektor $picc = "CACDEC6C5455EE52BB1DA40470963113"; // Hexadezimale Eingabe
// Konvertiere die Eingabe von Hex in Binär
$picc_binary = hex2bin($picc);
if ($picc_binary === false) {
die("Ungültige Hex-Eingabe"); }
// Entschlüsselung mit AES-128 im CBC-Modus
$decrypted = openssl_decrypt(
$picc_binary,
'aes-128-cbc',
$key,
OPENSSL_RAW_DATA,
$iv
);
if ($decrypted === false) {
die("Entschlüsselung fehlgeschlagen"); }
// Extrahiere den Zähler aus den Bytes 9 und 8
$counter = unpack('v', substr($decrypted, 8, 2)); // Little-Endian-Entpacken if ($counter === false) {
die("Konnte den Zähler nicht extrahieren"); }
$counter_value = $counter[1];
echo "hallo\n";
echo $counter_value . "\n";
echo "hallo\n";
}
// Führe die Funktion aus
decrypt_and_get_counter();
?>
PD9waHAKZnVuY3Rpb24gZGVjcnlwdF9hbmRfZ2V0X2NvdW50ZXIoKSB7CiAgICAkaXYgPSBzdHJfcmVwZWF0KCJceDAwIiwgMTYpOyAvLyBJbml0aWFsaXNpZXJ1bmdzdmVrdG9yCiAgICAka2V5ID0gc3RyX3JlcGVhdCgiXHgwMCIsIDE2KTsgLy8gQUVTLVNjaGzDvHNzZWwKICAgICRwaWNjID0gIkNBQ0RFQzZDNTQ1NUVFNTJCQjFEQTQwNDcwOTYzMTEzIjsgLy8gSGV4YWRlemltYWxlIEVpbmdhYmUKICAgIAogICAgLy8gS29udmVydGllcmUgZGllIEVpbmdhYmUgdm9uIEhleCBpbiBCaW7DpHIKICAgICRwaWNjX2JpbmFyeSA9IGhleDJiaW4oJHBpY2MpOwogICAgaWYgKCRwaWNjX2JpbmFyeSA9PT0gZmFsc2UpIHsKICAgICAgICBkaWUoIlVuZ8O8bHRpZ2UgSGV4LUVpbmdhYmUiKTsKICAgIH0KCiAgICAvLyBFbnRzY2hsw7xzc2VsdW5nIG1pdCBBRVMtMTI4IGltIENCQy1Nb2R1cw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