1
0
Fork 0
forked from fun/fun

Added sha384.fun to std library and alot of fixes. (0.16.3)

This commit is contained in:
Johannes Findeisen 2025-10-01 19:08:08 +02:00
commit 17241b2401
18 changed files with 820 additions and 314 deletions

View file

@ -29,3 +29,26 @@ print(typeof(x)) // -> "String"
// Typed byte must remain numeric (uint8):
// b = "oops" // Uncomment to see a runtime type error
/* Expected output:
=== byte with hex literal and clamping ===
255
255
255
=== for-loop reassigning a byte variable (shows clamping near the top end) ===
250
251
252
253
254
255
255
255
255
255
=== dynamic vs typed ===
Number
String
*/

View file

@ -32,6 +32,16 @@ print(md5.md5_hex("6d65737361676520646967657374")) // -> f96b697d7cb7938d525a2f
print(md5.md5_hex("6162636465666768696a6b6c6d6e6f707172737475767778797a")) // -> c3fcd3d76192e4007dfb496cca67e13b
// "Have Fun!"
print(md5.md5_str("Have Fun!")) // ->
print(md5.md5_str("Have Fun!")) // -> 852438d026c018c4307b916406f98c62
print("=== Done ===")
/* Expected output:
=== MD5 demo (hex input) ===
900150983cd24fb0d6963f7d28e17f72
d41d8cd98f00b204e9800998ecf8427e
f96b697d7cb7938d525a2f31aaf161d0
c3fcd3d76192e4007dfb496cca67e13b
812f2c01287af0e7c0a0b3daa381a51a
=== Done ===
*/

View file

@ -31,3 +31,12 @@ print(sha.sha256_hex("6d65737361676520646967657374")) // -> f7846f55cf23e14eebea
print(sha.sha256_hex("6162636465666768696a6b6c6d6e6f707172737475767778797a")) // -> 71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73
print("=== Done ===")
/* Expected output:
=== SHA-256 demo (hex input) ===
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
3859a4ec00dcbed7c01d4a462d18c1f4097a690a1d4d459be4e5b6f5a594ee68
de8ff7370090823795e96e3b7fbee3cfad374492417da99d72ba55297f7e58ab
5d3ed26c5e75585f56e664c0ebc63aa185ec606109f6374fefa42c862670d257
=== Done ===
*/

View file

@ -35,3 +35,14 @@ print(sha.sha256_str("6162636465666768696a6b6c6d6e6f707172737475767778797a")) //
print("=== Note ===")
print("sha256_str(\"616263\") hashes the text 616263; sha256_hex(\"616263\") hashes bytes 0x61 0x62 0x63 (abc).")
/* Expected output:
=== SHA-256 demo (raw string input via sha256_str) ===
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
3859a4ec00dcbed7c01d4a462d18c1f4097a690a1d4d459be4e5b6f5a594ee68
faee5966a2c104cf2287085428a183fe58c18afdc5ff261571e8e9c4796ad635
57aad00934af3b05086a755a1787884f2af6554dce4fc9cab02e7008d31dab44
a863dce86b2577846b6fd399ae6c9830999b4525c50b74705998f3df852b6d25
=== Note ===
sha256_str("616263") hashes the text 616263; sha256_hex("616263") hashes bytes 0x61 0x62 0x63 (abc).
*/

29
examples/sha384_example.fun Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-10-01
*/
/*
* Example: Using SHA384 from lib/crypt/sha384.fun
*
* Expected output for "abc":
* cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
*/
#include <crypt/sha384.fun>
s = SHA384()
// Hex input representing "abc"
print(s.sha384_hex("616263"))
// Raw string input
print(s.sha384_str("abc"))

View file

@ -33,3 +33,11 @@ print(sha.sha512_hex("6d65737361676520646967657374"))
// 3f36cc64dab6c0c5
print("=== Done ===")
/* Expected output:
=== SHA-512 demo (hex input) ===
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
107dbf389d9e9f71a3a95f6c055b9251bc5268c2be16d6c13492ea45b0199f3309e16455ab1e96118e8a905d5597b72038ddb372a89826046de66687bb420e7c
=== Done ===
*/

View file

@ -32,3 +32,12 @@ print(sha.sha512_str("616263")) // -> ee21095236a9c037f705f41ffa3cf60869891fcdb
print("=== Note ===")
print("sha512_str(\"616263\") hashes the text 616263; sha512_hex(\"616263\") hashes bytes 0x61 0x62 0x63 (abc).")
/* Expected output:
=== SHA-512 demo (raw string input via sha512_str) ===
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
ee21095236a9c037f705f41ffa3cf60869891fcdb461c5c8fe50e5b1711a27bfc02de2e387228651bdd034113cc59af777fdb9c915b70fdbed0eeacf7113296b
=== Note ===
sha512_str("616263") hashes the text 616263; sha512_hex("616263") hashes bytes 0x61 0x62 0x63 (abc).
*/