3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * http://stackoverflow.com/questions/9262109/php-simplest-two-way-encryption/30189841#30189841 * * This is not safe to use */ class UnsafeCrypto { const METHOD = 'aes-256-ctr'; /** * Encrypts (but does not authenticate) a message * * @param string $message - plaintext message * @param string $key - encryption key (raw binary expected) * @param boolean $encode - set to TRUE to return a base64-encoded * @return string (raw binary) */ public static function encrypt($message, $key, $encode = false) { $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = openssl_random_pseudo_bytes($nonceSize); $ciphertext = openssl_encrypt( $message, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); // Now let's pack the IV and the ciphertext together // Naively, we can just concatenate if ($encode) { return base64_encode($nonce.$ciphertext); } return $nonce.$ciphertext; } /** * Decrypts (but does not verify) a message * * @param string $message - ciphertext message * @param string $key - encryption key (raw binary expected) * @param boolean $encoded - are we expecting an encoded string? * @return string */ public static function decrypt($message, $key, $encoded = false) { if ($encoded) { $message = base64_decode($message, true); if ($message === false) { throw new Exception('Encryption failure'); } } $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = mb_substr($message, 0, $nonceSize, '8bit'); $ciphertext = mb_substr($message, $nonceSize, null, '8bit'); $plaintext = openssl_decrypt( $ciphertext, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); return $plaintext; } } $id = md5(uniqid()); var_dump($id); $key = hex2bin($id); var_dump($key); $message = 'Ready your ammunition; we attack at dawn.'; $encrypted = UnsafeCrypto::encrypt($message, $key); $decrypted = UnsafeCrypto::decrypt($encrypted, $key); var_dump($encrypted, $decrypted);
based on vsqNe
Output for 7.2.0
string(32) "f695716cf2a26a5e22b041537215c0e1" string(16) "��ql�j^"�ASr��" string(57) "-�]M�C� 7*��o�3"�V���hw����*�1�#В_���U,���,Yw��ĵ�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.10
string(32) "e040290396614a1b0a1b54b115bc4795" string(16) "�@)�aJ T��G�" string(57) "ϕg��Wa���OKz%,(���G�5�.7a.�֤�v��l8�f���]"�Ϧ�>��S4" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.7
string(32) "ff428eb4e255f587ae97166faa664ac8" string(16) "�B���U����o�fJ�" string(57) "�U�i���ť3�=^W9!i��V�~Z���� ��M0��Pr�1�Zvc\o" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.6
string(32) "be3ddb0738f0180cab9c4228ec781ccb" string(16) "�=�8� ��B(�x�" string(57) "��h��G*[�$F��w/فg�X�M�c��*�c���F���t�I{�Y��$ݡ}j:" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.5
string(32) "c7a5f038beb6734cd594fa3c65054b32" string(16) "ǥ�8��sLՔ�<eK2" string(57) "�0a����i�cUǺ�� ��ׇ�}�O��3�)8��y.���]6��{ɢ�Hl+s" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.4
string(32) "ef6126cc7d34051d321d4c24f0b9793a" string(16) "�a&�}42L$�y:" string(57) "镺TT*6;0�Ry�pY�q����f;�.&J�/�F�C�2�����T��G�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.3
string(32) "63f6c55cbe293599790ba4339be32111" string(16) "c��\�)5�y �3��!" string(57) "��qF.tWп)�(��l���/@��u�i =�j8��� �_�<�17d.�3�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.2
string(32) "473ced3f8989aa4c4574e5897ea434fe" string(16) "G<�?���LEt�~�4�" string(57) "Rsn�>�LE���M�����~�������*����옏�k �fA��]Ҳ#�K�A*" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.1
string(32) "83188503f8daac0a776968e7c9e352ca" string(16) "���ڬ wih���R�" string(57) "���#��4�r��LJ���T�$o �U�]w�ӜH��ZoV�ق?[���06%y�& U\" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.0
string(32) "c8e7eae32cd708c24ebd6b2a7407a495" string(16) "����,��N�k*t��" string(57) "@/*�:�F4/<�z��HL(�J�ڹ �gt��Q�O����a�} dK:-�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.20
string(32) "ac9aa5472df098b21362706c910861ad" string(16) "���G-�bpl�a�" string(57) "���O�5���$�W�-BR����M1�Ge��BJ)bl��ݚ�yj�\5_!K�1��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.19
string(32) "b98c18f0fe682dc226b2d864749aaa5a" string(16) "���h-�&��dt��Z" string(57) "ُL;�Vg��m!W'-=_�nb��X��eQ �ĵĦ� ��is~4F3J���}ą�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.18
string(32) "cf7e559ede79170c15b00e53d131dd74" string(16) "�~U��y �S�1�t" string(57) "�c�M�F�\><�aN��G����t�4��l����͛��G�~��*+�I��|�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.17
string(32) "295e8bf5032145d517d8a59ed2fdab73" string(16) ")^��!E�إ���s" string(57) ";Ԏs']� ֈ�?�uL�]ύ�;Z]���O�����b[s��< �`�Pb�=q(�w�3�;" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.16
string(32) "47995e34d12eb33a199e540f09212511" string(16) "G�^4�.�:�T !%" string(57) ";�&?e"�O�>�=xsg�b��"�� ��[CF� J6��I��H$&�>>� l" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.15
string(32) "b5280bcda3401a3d0baa53bd09612afc" string(16) "�( ͣ@= �S� a*�" string(57) "=�_���b�@A��.�"�=�w��m� c}T���)�>��G�N%� b�u!�9$�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.14
string(32) "5cc32f427212a936ec24092478230703" string(16) "\�/Br�6�$ $x#" string(57) "�=gX�R��;�^�d 'Gi�a��E�?�{'z�T�Ǝ@��P`��V� �j������2�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.13
string(32) "13f6149638d10c7b4c534ae1c68cce35" string(16) "��8� {LSJ�ƌ�5" string(57) "���9<e���- ���V�n}m�e�C��7f[&U��r� nŐ��7�P" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.12
string(32) "3b536e5fd1648c123a1029c4dfd34f74" string(16) ";Sn_�d�:)���Ot" string(57) "�7筛~1���?�߱�W]t�>3Yf\�3� ��ú9���CH���0��N�v�o" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.11
string(32) "776e8ff357286f053de25938c3e641c4" string(16) "wn��W(o=�Y8��A�" string(57) "��CEJ�p[e�fd��C�)ȋ��A�u���'Oq��,��a+8\� � �" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.10
string(32) "bf5eb4ef8a01b090d1a1afca949099c7" string(16) "�^����ѡ�ʔ���" string(57) "��(ݻv�Ϥ��'��W! �uq|�H>���iƯ�a�eg|WD����3�� �" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.9
string(32) "f36a3d084523cd5ec8fdb4c6c819d9b2" string(16) "�j=E#�^����ٲ" string(57) "Xc� T�����%(�?��B�(�#쩭=ղ� ����.�jZ��ޔz��c�`|o^" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.8
string(32) "f5c2666865a0c960b99028cb47cf2d26" string(16) "��fhe��`��(�G�-&" string(57) "p�{�|�$iMc�|%Q���� ʟ'l��=�`���"4H�����Y��~b0�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.7
string(32) "655703b8c67d291272e42a509d327d0d" string(16) "eW��})r�*P�2} " string(57) "��8���_�v@�j�����_�!h��_��3��a���y�G!H���H)���: �" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.6
string(32) "75184d676d1b6ff854c94c9f21e55deb" string(16) "uMgmo�T�L�!�]�" string(57) "�X �D�0ey�~�㒴-~q���y4[���Έ#��L�@�� ����a)��*��� " string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.5
string(32) "e954f02455172cb5a8785df1c2c1f6d6" string(16) "�T�$U,��x]����" string(57) "���(�Ȋq����mb��ͭT�)���a��Τ�`ج�;7���.Pe���6" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.4
string(32) "0dffa766df34a4b595fedd8ffca84cd3" string(16) " ��f�4����ݏ��L�" string(57) "V��� �-#hBc�tB@H�S�dJ�� ~�6� c��1��m<�ӊ�DHz�� " string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.3
string(32) "316c6ef7b02519346e6550b4283b0513" string(16) "1ln��%4neP�(;" string(57) "���2EыPZ?���xl�&x�<��b�d��W8���b���y��Ҷ�\���=[�)�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.2
string(32) "a0cc94ce7fe37005c3695f3c893237b4" string(16) "�̔��p�i_<�27�" string(57) "xy�X Qk�T��������8qOK��'GhA�eЭ�ӲT7��-�괪^1up�[I��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.1
string(32) "587d94eddea349ab2a55d3356dc768ff" string(16) "X}��ޣI�*U�5m�h�" string(57) "\y�������~#�E6���3 xw4�d�&�B�*h'�vE: �� �� �������" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.0
string(32) "3eb9cd5e7c8cee51d2fd5dfca06bb382" string(16) ">��^|��Q�]��k��" string(57) "N���$ �8v�w��|��W'҆��nfN������(qIK�v����,P�㦿�%" string(41) "Ready your ammunition; we attack at dawn."
Output for hhvm-3.15.4
string(32) "58a08d22e325cac5b1ad7e985c66e9be" string(16) "X��"�%�ű�~�\f�" string(57) "� "�dwkL$*je v�����hUc5;�ߕ$��Ĥ�-��W2g�CP��/�e ��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.30
string(32) "4499738c74ddb87bac661e9460133d9b" string(16) "D�s�tݸ{�f�`=�" string(57) "�vİ!"��޷™��D�R� �>:�H� ���)�>��~Y�� jy��ǵ7V�D��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.29
string(32) "819eeae61356670a390b9dc5ca59092c" string(16) "����Vg 9 ���Y ," string(57) "��D)"Obr���Cd|K�����N_�]��I1 �̳XY[&�ׄ���n�2�O'��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.28
string(32) "fde14b81219154d94fb3404f754099b9" string(16) "��K�!�T�O�@Ou@��" string(57) ".D+-�u�}�'���=��,-�y�r<R�0d��qc1�>��1!�vBf���!��V" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.27
string(32) "2f1ca7ecb2138ce2b10bc12755726e7d" string(16) "/���� �'Urn}" string(57) "G7"�����_-=���.V�חO�@���a�a�:�H|����U�oL��ml: �d6" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.26
string(32) "6319890341f9079f5354395742faa08b" string(16) "c�A��ST9WB���" string(57) "?��U6��rAK�� ��F�gJ�dX��!/j[�� �ƙ�t�� Ŝ��5����ؒ" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.25
string(32) "a67f9120d7112a0de262957911362d3c" string(16) "�� �* �b�y6-<" string(57) "d)�Q�x/�VWh=���^#a������H�dZ���O��{��*i͢KU �J47\�2" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.24
string(32) "dad383806aa30096c614a3585f4984ec" string(16) "�Ӄ�j����X_I��" string(57) "��ud� � ���r��>zn�H�X�]$�DX���JvJ�I��R8 ѼB�%��/�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.23
string(32) "28673973d78618bef53b88d9e420faa5" string(16) "(g9s׆��;��� ��" string(57) "��t��d�s�,�����wpx:qЛ�_�re)�r(܍P{wf��K�Y���]N�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.22
string(32) "54810fd7b7d5a26d97d150bda4f8df28" string(16) "T�׷բm��P����(" string(57) "D���&�"�2�d?M�%F�csG1.':d�#����l��92����5TQ[;�JA�X" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.21
string(32) "d6e1219d99e4f2be8bbaaefe8e4bc43b" string(16) "��!���򾋺���K�;" string(57) "�� �_�Ј @G���/b��M���" ģŶ}ÒJI��f�D�J7�^" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.20
string(32) "af946aafb7f0278a9de29521f6f21dd0" string(16) "��j���'���!���" string(57) ""��V���T绸)W��I����>�D�&���H XM^t���,~�ށQho�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.19
string(32) "373653b6ae3e382e9679187f1ed7a53d" string(16) "76S��>8.�yץ=" string(57) "��^�U` M=�c:�p�V�l: `�~\0��ؑ��aՏj�)��t�+%���;" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.18
string(32) "7ba791dc9b7cbfc35a4c9574076b3669" string(16) "{��ܛ|��ZL�tk6i" string(57) "�����0��@�|���F"+Q~�X�!��V%��U����O?uͯ�R<JC�8���r" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.17
string(32) "6a68b115cb3b311c923ed5243897d710" string(16) "jh��;1�>�$8��" string(57) "���+�X�]DijLP�O�f۩@5-����Ȇ� �|C�f�\�O�o����R=" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.16
string(32) "725c15fc50749fb6158df8d677a16f81" string(16) "r\�Pt�����w�o�" string(57) "�n4_����"�vZ�bۤ�9w�dn�t���$v�~F G�ɋ��@��)�H&-w* " string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.15
string(32) "dbc8418d475281973d51364ff67c46d4" string(16) "��A�GR��=Q6O�|F�" string(57) "V��� 0���G�9z2 ��-�d����`���e�_��&{�a� QMe�2�/bQ�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.14
string(32) "1cda801e02ba8df05aa9527d6c6d4d95" string(16) "ڀ���Z�R}lmM�" string(57) "ߡ�f�ď�)\�n��U�PX���%a�� 4rұ�u�ϖ�lL�?��/�+��e�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.13
string(32) "aafd63bc8bb516400ce1fa38928a49fb" string(16) "��c���@ �8��I�" string(57) "��\h��T~�u]ƾ�7!��c֐Q�լ��õ* ����4��ٴY/h(�qօ�e" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.12
string(32) "88fd2001b0ce0419f74d9f80730b8ad1" string(16) "�� ���M��s ��" string(57) "��S��h����������͙���� �Xw�̣g�6)��2��,�ј�N\|:" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.11
string(32) "9eb9a62374d553e13adb44fdfda346aa" string(16) "���#t�S�:�D���F�" string(57) "���l����g��R�:�#���fERr�����,�ep�� ��+��na���" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.10
string(32) "4260cb098d4080b4dc57c30e9542c2a9" string(16) "B`� �@���W��B©" string(57) "��C?5�RNÜ�Ş}��y*st >��]G�6��u�����@���"���x�F��ӳ" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.9
string(32) "d593a8205440ed5e19ae2ca091d4374b" string(16) "Փ� T@�^�,���7K" string(57) "��N�TH)���4�ED�_�&��`[%ۃܞ��_+����䆻r��mac�z�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.8
string(32) "11a2831b310d022ef0ed5c6228e65db7" string(16) "��1 .��\b(�]�" string(57) "��_�E�?�ϒ�~�;�.;���2��T �ͯ�^t�<��Zp��8!�AOm� ��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.7
string(32) "66672562e150b9d611c5459d238e459b" string(16) "fg%b�P���E�#�E�" string(57) "��)��[�Ҏw�鐲�Go��j��F��ۏ����A��o �J��Ӛ�� �" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.6
string(32) "ad1609beb7c5d1b7c8d6eecdc28c9535" string(16) "� ���ѷ����Œ�5" string(57) "E�*V�����@��Ń�r!�;�A��р��E�,�w9`��T�NH V�P�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.5
string(32) "26495c66e3ae5f464b4da14752583bb8" string(16) "&I\f�_FKM�GRX;�" string(57) "������q����j�MXHj��F� $�V����F�2w(�� ��~� � 5�?0uH�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.4
string(32) "fe034ee385879420d00ad2e50e0cc2f3" string(16) "�Nㅇ� � �� ��" string(57) "�]�1D�.�`mV�t���R���n��H�4�Y]a�\O�ٺ��ۢ��E" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.3
string(32) "dba2386c94a74e591f87a472b6d55601" string(16) "ۢ8l��NY��r��V" string(57) "����W�6e}�i-��60�64�c��D&K��X����8& ϵA���l�ǽ��� ���" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.2
string(32) "603f88523781ab466620da6946873700" string(16) "`?�R7��Ff �iF�7" string(57) "��=�Gc��g-�(��{ GF��7%�u������*��T���o$$�]��h���" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.1
string(32) "0835eca2624823cc9e45ff6abf9df323" string(16) "5�bH#̞E�j���#" string(57) "�޾�c�A�f��$���NM'�M ØkJ��.? ��tq2�S,I|d1���/�A� " string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.0
string(32) "16afe0db118346d2af12fbe675691270" string(16) "����Fү��uip" string(57) "������Mf,/�5\� sR= O"Է�!)H��D��i$�H��mGs�9�AJl;2�8�" string(41) "Ready your ammunition; we attack at dawn."