PHP Classes
elePHPant
Icontem

File: src/Transformation/LastFourDigits.php

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  Cipher Sweet  >  src/Transformation/LastFourDigits.php  >  Download  
File: src/Transformation/LastFourDigits.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Cipher Sweet
Encrypt data in away that can be searched
Author: By
Last change:
Date: 8 months ago
Size: 820 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\CipherSweet\Transformation;

use
ParagonIE\ConstantTime\Binary;
use
ParagonIE\CipherSweet\Contract\TransformationInterface;

/**
 * Class LastFourDigits
 * @package ParagonIE\CipherSweet\Transformation
 */
class LastFourDigits implements TransformationInterface
{
   
/**
     * Returns the last 4 digits (e.g. for a social security or credit card
     * number). If less then 4 digits are available, it will pad them with 0
     * characters to the left.
     *
     * 1234567890 => 7890
     * 123 => 0123
     *
     * @param string $input
     * @return string
     */
   
public function __invoke($input)
    {
       
$input = \preg_replace('/[^0-9]/', '', $input);
       
$input = \str_pad($input, 4, '0', STR_PAD_LEFT);
        return
Binary::safeSubstr($input, -4, 4);
    }
}