简体   繁体   English

如何使用 php 的 SHA1 函数生成哈希/Base64 输出列表?

[英]How to use php's SHA1 function to generate a list of hash/Base64 outputs?

I want to use PHP's SHA1 function to generate a list of hash/Base64 outputs from a single string.我想使用 PHP 的 SHA1 函数从单个字符串生成哈希/Base64 输出列表。

For example, if I have a string, "ABCDE"例如,如果我有一个字符串,“ABCDE”

Then I want to generate 5 outputs like:然后我想生成 5 个输出,如:

echo sha1('ABCDE');
echo sha1('BCDE');
echo sha1('CDE');
echo sha1('DE');
echo sha1('E');

And the number of outputs will match the length of the string.并且输出的数量将匹配字符串的长度。 How would I accomplish this?我将如何实现这一点?

<?php
$s = 'ABCDE';
$t = strlen($s);
for ($i = 1; $i <= $t; $i++) {
  echo sha1($s);
  echo '</br>';
  $s = substr($s, 1);
}
?>

I use a for loop but you can use while too.我使用 for 循环,但您也可以使用while I don't know how to.我不知道该怎么做。

It was annoying me, this is the easiest by far.这让我很烦,这是迄今为止最简单的。

$str = 'ABCDE';
while (strlen($str)) {
    echo sha1($str);
    $str = substr($str, 1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM