mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 22:14:53 +00:00
Add a function for getting a quick hash/checksum
16 bits ought to be enough for anything
This commit is contained in:
parent
1b6ef6670f
commit
6858abac04
1 changed files with 10 additions and 0 deletions
10
share/functions/fish_fletcher16.fish
Normal file
10
share/functions/fish_fletcher16.fish
Normal file
|
@ -0,0 +1,10 @@
|
|||
function fish_fletcher16 --argument input -d "compute a fletcher 16 checksum"
|
||||
set -l sum1 0
|
||||
set -l sum2 0
|
||||
for char in (string split '' $input)
|
||||
set -l ordinal (printf %2u "'$char")
|
||||
math "($sum1 + $ordinal)" % 255 | read sum1
|
||||
math "($sum2 + $sum1)" % 255 | read sum2
|
||||
end
|
||||
math "bitor $sum1,$(math $sum2 '*' pow 2,8)"
|
||||
end
|
Loading…
Reference in a new issue