Source of file QwertyConvertor.php
Size: 2,315 Bytes - Last Modified: 2021-12-24T06:47:50+00:00
/var/www/docs.ssmods.com/process/src/src/Helpers/QwertyConvertor.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php namespace Firesphere\YubiAuth\Helpers; /** * @description Helper Class to convert different keyboard layouts to Qwerty before authenticating */ class QwertyConvertor { /** * @var string Dvorak layout */ protected static $dvorak = "[]',.pyfgcrl/=aoeuidhtns-;qjkxbmwvz{}\"<>PYFGCRL?+AOEUIDHTNS_:QJKXBMWVZ"; /** * @var string Qwerty layout */ protected static $qwerty = "-=qwertyuiop[]asdfghjkl;'zxcvbnm,./_+QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?"; /** * This might be tricky to detect, as the initial position of C seems to be the same * * @var string Azerty layout conversion */ protected static $azerty = ")-azertyuiop^\$qsdfghjklmùwxcvbn,;:=°_AZERTYUIOP¨*QSDFGHJKLM%WXCVBN?./+"; /** * Detect different keyboard layouts and return the converted string. * A Yubi-string alsways starts with `cccccc`. If it's different, we have a different layout. * Dvorak is easy to detect. Azerty on the other hand, might be tricky. * Other conversion additions welcome. * * @param string $yubiString * * @return string */ public static function convertString($yubiString) { $yubiString = strtolower($yubiString); /* The string is Dvorak, convert it to QWERTY */ if (strpos($yubiString, 'jjjjjj') === 0) { return self::convertToQwerty($yubiString, static::$dvorak); } /* Azerty has some odd characters which we can use to detect it */ if ( strpos($yubiString, '°') !== false || strpos($yubiString, '¨') !== false || strpos($yubiString, '$') !== false ) { return self::convertToQwerty($yubiString, static::$azerty); } return $yubiString; } /** * @param string $originalString * @param string $from Origin we have to convert from * * @return string */ public static function convertToQwerty($originalString, $from) { $originalArray = str_split($originalString); $qwerty = str_split(self::$qwerty); $from = str_split($from); $return = ''; foreach ($originalArray as $item) { $return .= $qwerty[array_search($item, $from, true)]; } return $return; } } |