<?php

function encrypt($plaintext, $key  = '17 d8 98 b5 ce ce e1 09 8b 56')
{
   /*$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
   $method = 'aes-256-cbc';
   $encrypted = base64_encode(openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv));
   */
   $ciphering = "AES-128-CTR"; 
   $options = 0; 
   $encryption_key = "GeeksforGeeks"; 
   $encryption_iv = '1234567891011121'; 
   $encrypted = base64_encode_url(openssl_encrypt($plaintext, $ciphering, $encryption_key, $options, $encryption_iv)); 
   
   return  ($encrypted) ;
}

/**
 * Verify HMAC-SHA-512 then decrypt AES-256-CTR
 * 
 * @param string $message Encrypted message
 * @param string $encryptionKey Key for encryption
 * @param string $macKey Key for calculating the MAC
 */
function decrypt($encrypted, $key  = '17 d8 98 b5 ce ce e1 09 8b 56')
{
   /*$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
   $method = 'aes-256-cbc';
   $decrypted = openssl_decrypt(base64_decode($encrypted), $method, $key, OPENSSL_RAW_DATA, $iv);
   */
   $ciphering = "AES-128-CTR"; 
   $options = 0;
   $decryption_key = "GeeksforGeeks"; 
   $decryption_iv = '1234567891011121'; 
   $decrypted=openssl_decrypt (base64_decode_url($encrypted), $ciphering,  $decryption_key, $options, $decryption_iv); 
		
   return $decrypted; 
}

function base64_encode_url($string) {
    return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}

function base64_decode_url($string) {
    return base64_decode(str_replace(['-','_'], ['+','/'], $string));
}

function encrypt_full($plaintext, $key  = '17 d8 98 b5 ce ce e1 09 8b 56')
{
   /*$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
   $method = 'aes-256-cbc';
   $encrypted = base64_encode(openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv));
   */
   $ciphering = "AES-128-CTR"; 
   $options = 0; 
   $encryption_key = "GeeksforGeeks"; 
   $encryption_iv = '1234567891011121'; 
   $encrypted =openssl_encrypt(base64_encode($plaintext), $ciphering, 
   $encryption_key, $options, $encryption_iv); 
   
   return  ($encrypted) ;
}

/**
 * Verify HMAC-SHA-512 then decrypt AES-256-CTR
 * 
 * @param string $message Encrypted message
 * @param string $encryptionKey Key for encryption
 * @param string $macKey Key for calculating the MAC
 */
function decrypt_full($encrypted, $key  = '17 d8 98 b5 ce ce e1 09 8b 56')
{
   /*$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
   $method = 'aes-256-cbc';
   $decrypted = openssl_decrypt(base64_decode($encrypted), $method, $key, OPENSSL_RAW_DATA, $iv);
   */
   $ciphering = "AES-128-CTR"; 
   $options = 0;
   $decryption_key = "GeeksforGeeks"; 
   $decryption_iv = '1234567891011121'; 
   $decrypted=openssl_decrypt ($encrypted, $ciphering,  
        $decryption_key, $options, $decryption_iv); 
		
   return (base64_decode($decrypted)); 
}