File path refactoring. No code changes. (0.37.51)
This commit is contained in:
parent
2fa8f8653e
commit
db68b30d5b
27 changed files with 0 additions and 0 deletions
54
examples/crypto/crc32_example.fun
Executable file
54
examples/crypto/crc32_example.fun
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-11-26
|
||||
*/
|
||||
|
||||
// Example: Using the CRC32 class from lib/crypt/crc32.fun
|
||||
|
||||
include <crypt/crc32.fun>
|
||||
|
||||
print("-- CRC32 example --")
|
||||
|
||||
c = CRC32()
|
||||
|
||||
// 1) Known test vector: "123456789" -> cbf43926
|
||||
msg = "123456789"
|
||||
crc1 = c.crc32_str(msg)
|
||||
print("Input (ASCII): " + msg)
|
||||
print("CRC32: " + crc1) // expected: cbf43926
|
||||
|
||||
print("")
|
||||
|
||||
// 2) Same data provided as hex string
|
||||
hex_msg = "313233343536373839" // hex for "123456789"
|
||||
crc2 = c.crc32_hex(hex_msg)
|
||||
print("Input (hex): " + hex_msg)
|
||||
print("CRC32: " + crc2) // expected: cbf43926
|
||||
|
||||
print("")
|
||||
|
||||
// 3) Another quick demo
|
||||
other = "Fun language"
|
||||
crc3 = c.crc32_str(other)
|
||||
print("Input (ASCII): " + other)
|
||||
print("CRC32: " + crc3)
|
||||
|
||||
/* Expected output:
|
||||
-- CRC32 example --
|
||||
Input (ASCII): 123456789
|
||||
CRC32: cbf43926
|
||||
|
||||
Input (hex): 313233343536373839
|
||||
CRC32: cbf43926
|
||||
|
||||
Input (ASCII): Fun language
|
||||
CRC32: d7d83272
|
||||
*/
|
||||
54
examples/crypto/crc32c_example.fun
Executable file
54
examples/crypto/crc32c_example.fun
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-11-26
|
||||
*/
|
||||
|
||||
// Example: Using the CRC32C class from lib/crypt/crc32c.fun
|
||||
|
||||
include <crypt/crc32c.fun>
|
||||
|
||||
print("-- CRC32C example --")
|
||||
|
||||
c = CRC32C()
|
||||
|
||||
// 1) Known test vector: "123456789" -> e3069283
|
||||
msg = "123456789"
|
||||
crc1 = c.crc32c_str(msg)
|
||||
print("Input (ASCII): " + msg)
|
||||
print("CRC32C: " + crc1) // expected: e3069283
|
||||
|
||||
print("")
|
||||
|
||||
// 2) Same data provided as hex string
|
||||
hex_msg = "313233343536373839" // hex for "123456789"
|
||||
crc2 = c.crc32c_hex(hex_msg)
|
||||
print("Input (hex): " + hex_msg)
|
||||
print("CRC32C: " + crc2) // expected: e3069283
|
||||
|
||||
print("")
|
||||
|
||||
// 3) Another quick demo
|
||||
other = "Fun language"
|
||||
crc3 = c.crc32c_str(other)
|
||||
print("Input (ASCII): " + other)
|
||||
print("CRC32C: " + crc3)
|
||||
|
||||
/* Expected output:
|
||||
-- CRC32C example --
|
||||
Input (ASCII): 123456789
|
||||
CRC32C: e3069283
|
||||
|
||||
Input (hex): 313233343536373839
|
||||
CRC32C: e3069283
|
||||
|
||||
Input (ASCII): Fun language
|
||||
CRC32C: c0158b58
|
||||
*/
|
||||
51
examples/crypto/md5_demo.fun
Executable file
51
examples/crypto/md5_demo.fun
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-09-29
|
||||
*/
|
||||
|
||||
// Include the pure Fun MD5 library
|
||||
include <crypt/md5.fun>
|
||||
|
||||
// create a hasher instance
|
||||
md5 = MD5()
|
||||
|
||||
print("=== MD5 demo (hex input) ===")
|
||||
|
||||
// "abc" => 0x61 0x62 0x63
|
||||
print(md5.md5_hex("616263")) // -> 900150983cd24fb0d6963f7d28e17f72
|
||||
|
||||
// empty string "" => hex ""
|
||||
print(md5.md5_hex("")) // -> d41d8cd98f00b204e9800998ecf8427e
|
||||
|
||||
// "message digest"
|
||||
print(md5.md5_hex("6d65737361676520646967657374")) // -> f96b697d7cb7938d525a2f31aaf161d0
|
||||
|
||||
// "abcdefghijklmnopqrstuvwxyz"
|
||||
print(md5.md5_hex("6162636465666768696a6b6c6d6e6f707172737475767778797a")) // -> c3fcd3d76192e4007dfb496cca67e13b
|
||||
|
||||
// "Have Fun!"
|
||||
print(md5.md5_str("Have Fun!")) // -> 812f2c01287af0e7c0a0b3daa381a51a
|
||||
|
||||
// More MD5
|
||||
print(md5.md5_str("a")) // -> 0cc175b9c0f1b6a831c399e269772661
|
||||
|
||||
print("=== Done ===")
|
||||
|
||||
/* Expected output:
|
||||
=== MD5 demo (hex input) ===
|
||||
900150983cd24fb0d6963f7d28e17f72
|
||||
d41d8cd98f00b204e9800998ecf8427e
|
||||
f96b697d7cb7938d525a2f31aaf161d0
|
||||
c3fcd3d76192e4007dfb496cca67e13b
|
||||
812f2c01287af0e7c0a0b3daa381a51a
|
||||
0cc175b9c0f1b6a831c399e269772661
|
||||
=== Done ===
|
||||
*/
|
||||
154
examples/crypto/ripemd160_debug.fun
Executable file
154
examples/crypto/ripemd160_debug.fun
Executable file
|
|
@ -0,0 +1,154 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-12-27
|
||||
*/
|
||||
|
||||
#include <crypt/ripemd160.fun>
|
||||
|
||||
fun to_hex_32(v)
|
||||
d = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
|
||||
out = []
|
||||
i = 0
|
||||
while i < 4
|
||||
b = band(shr(v, (3 - i) * 8), 0xFF)
|
||||
push(out, d[shr(b, 4)])
|
||||
push(out, d[band(b, 0xF)])
|
||||
i = i + 1
|
||||
return join(out, "")
|
||||
|
||||
rmd = RIPEMD160()
|
||||
state = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]
|
||||
block = []
|
||||
push(block, 128) // 0x80
|
||||
i = 1
|
||||
while i < 64
|
||||
push(block, 0)
|
||||
i = i + 1
|
||||
|
||||
print("Initial state:")
|
||||
for v in state
|
||||
print(" " + to_hex_32(v))
|
||||
|
||||
// Manual process_block logic with prints
|
||||
M = []
|
||||
i = 0
|
||||
while i < 16
|
||||
j = i * 4
|
||||
push(M, rmd.word32_le(block[j], block[j+1], block[j+2], block[j+3]))
|
||||
i = i + 1
|
||||
|
||||
al = state[0]
|
||||
bl = state[1]
|
||||
cl = state[2]
|
||||
dl = state[3]
|
||||
el = state[4]
|
||||
ar = state[0]
|
||||
br = state[1]
|
||||
cr = state[2]
|
||||
dr = state[3]
|
||||
er = state[4]
|
||||
|
||||
j = 0
|
||||
while j < 80
|
||||
if j < 16
|
||||
stage = 0
|
||||
stage_r = 4
|
||||
else if j < 32
|
||||
stage = 1
|
||||
stage_r = 3
|
||||
else if j < 48
|
||||
stage = 2
|
||||
stage_r = 2
|
||||
else if j < 64
|
||||
stage = 3
|
||||
stage_r = 1
|
||||
else
|
||||
stage = 4
|
||||
stage_r = 0
|
||||
|
||||
f = rmd.F(stage, bl, cl, dl)
|
||||
TL1 = rmd.add32(al, f)
|
||||
TL2 = rmd.add32(M[rmd.RL[j]], rmd.KL[stage])
|
||||
TL3 = rmd.add32(TL1, TL2)
|
||||
TL4 = rmd.rol32(TL3, rmd.SL[j])
|
||||
TL = rmd.add32(TL4, el)
|
||||
if j < 2
|
||||
print("j=" + to_string(j) + " L: al=" + to_hex_32(al) + " f=" + to_hex_32(f) + " TL3=" + to_hex_32(TL3) + " TL4=" + to_hex_32(TL4) + " TL=" + to_hex_32(TL))
|
||||
al = el
|
||||
el = dl
|
||||
dl = rmd.rol32(cl, 10)
|
||||
cl = bl
|
||||
bl = TL
|
||||
|
||||
fr = rmd.F(stage_r, br, cr, dr)
|
||||
TR1 = rmd.add32(ar, fr)
|
||||
TR2 = rmd.add32(M[rmd.RR[j]], rmd.KR[stage])
|
||||
TR3 = rmd.add32(TR1, TR2)
|
||||
TR4 = rmd.rol32(TR3, rmd.SR[j])
|
||||
TR = rmd.add32(TR4, er)
|
||||
if j < 2
|
||||
print("j=" + to_string(j) + " R: ar=" + to_hex_32(ar) + " fr=" + to_hex_32(fr) + " TR3=" + to_hex_32(TR3) + " TR4=" + to_hex_32(TR4) + " TR=" + to_hex_32(TR))
|
||||
ar = er
|
||||
er = dr
|
||||
dr = rmd.rol32(cr, 10)
|
||||
cr = br
|
||||
br = TR
|
||||
|
||||
if j == 0
|
||||
print("After j=0:")
|
||||
print(" L: al=" + to_hex_32(al) + " bl=" + to_hex_32(bl) + " cl=" + to_hex_32(cl) + " dl=" + to_hex_32(dl) + " el=" + to_hex_32(el))
|
||||
print(" R: ar=" + to_hex_32(ar) + " br=" + to_hex_32(br) + " cr=" + to_hex_32(cr) + " dr=" + to_hex_32(dr) + " er=" + to_hex_32(er))
|
||||
|
||||
j = j + 1
|
||||
|
||||
print("Registers after 80 steps:")
|
||||
print(" L: A=" + to_hex_32(al) + " B=" + to_hex_32(bl) + " C=" + to_hex_32(cl) + " D=" + to_hex_32(dl) + " E=" + to_hex_32(el))
|
||||
print(" R: Ar=" + to_hex_32(ar) + " Br=" + to_hex_32(br) + " Cr=" + to_hex_32(cr) + " Dr=" + to_hex_32(dr) + " Er=" + to_hex_32(er))
|
||||
|
||||
h0 = rmd.add32(state[1], rmd.add32(cl, dr))
|
||||
h1 = rmd.add32(state[2], rmd.add32(dl, er))
|
||||
h2 = rmd.add32(state[3], rmd.add32(el, ar))
|
||||
h3 = rmd.add32(state[4], rmd.add32(al, br))
|
||||
h4 = rmd.add32(state[0], rmd.add32(bl, cr))
|
||||
state[0] = h0
|
||||
state[1] = h1
|
||||
state[2] = h2
|
||||
state[3] = h3
|
||||
state[4] = h4
|
||||
|
||||
print("Final state:")
|
||||
for v in state
|
||||
print(" " + to_hex_32(v))
|
||||
|
||||
/* Possible output:
|
||||
Initial state:
|
||||
67452301
|
||||
efcdab89
|
||||
98badcfe
|
||||
10325476
|
||||
c3d2e1f0
|
||||
j=0 L: al=67452301 f=67452301 TL3=ce8a4682 TL4=52341674 TL=1606f864
|
||||
j=0 R: ar=67452301 fr=10325476 TR3=c81a035d TR4=1a035dc8 TR=ddd63fb8
|
||||
After j=0:
|
||||
L: al=c3d2e1f0 bl=1606f864 cl=efcdab89 dl=eb73fa62 el=10325476
|
||||
R: ar=c3d2e1f0 br=ddd63fb8 cr=efcdab89 dr=eb73fa62 er=10325476
|
||||
j=1 L: al=c3d2e1f0 f=12b8a98f TL3=d68b8b7f TL4=e2dff5a2 TL=f3124a18
|
||||
j=1 R: ar=c3d2e1f0 fr=221b9025 TR3=3690fdfb TR4=21fbf66d TR=322e4ae3
|
||||
Registers after 80 steps:
|
||||
L: A=594637a7 B=215d97b3 C=eba027eb D=b99cdc7a E=ec4dcdff
|
||||
R: Ar=e7eb2e49 Br=85bff1f4 Cr=1d9bc99d Dr=a7ffa90b Er=ffcec761
|
||||
Final state:
|
||||
836d7c7f
|
||||
522680d9
|
||||
e46b50be
|
||||
a2d90b8b
|
||||
a63e8451
|
||||
*/
|
||||
58
examples/crypto/ripemd160_demo.fun
Executable file
58
examples/crypto/ripemd160_demo.fun
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-12-27
|
||||
*/
|
||||
|
||||
// THIS IS BROKEN ACTUALLY! IT DOES NOT CALCULATE THE EXPECTED HASHES!
|
||||
|
||||
// Example usage of the RIPEMD-160 hash algorithm.
|
||||
|
||||
#include <crypt/ripemd160.fun>
|
||||
|
||||
rmd = RIPEMD160()
|
||||
|
||||
// Test case 1: Empty string
|
||||
s1 = ""
|
||||
h1 = rmd.ripemd160_str(s1)
|
||||
print("RIPEMD-160(\"" + s1 + "\") = " + h1)
|
||||
// Expected: 9c1185a5c5e9fc54612808977ee8f548b2258d31
|
||||
|
||||
// Test case 2: "abc"
|
||||
s2 = "abc"
|
||||
h2 = rmd.ripemd160_str(s2)
|
||||
print("RIPEMD-160(\"" + s2 + "\") = " + h2)
|
||||
// Expected: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
|
||||
|
||||
// Test case 3: "message digest"
|
||||
s3 = "message digest"
|
||||
h3 = rmd.ripemd160_str(s3)
|
||||
print("RIPEMD-160(\"" + s3 + "\") = " + h3)
|
||||
// Expected: 5d0689ef49d2fae572b881b123a85ffa21595f36
|
||||
|
||||
// Example of hashing from hex string
|
||||
hex_input = "616263" // "abc" in hex
|
||||
h4 = rmd.ripemd160_hex(hex_input)
|
||||
print("RIPEMD-160(hex: " + hex_input + ") = " + h4)
|
||||
// Expected: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
|
||||
|
||||
/* Expected output:
|
||||
RIPEMD-160("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31
|
||||
RIPEMD-160("abc") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
|
||||
RIPEMD-160("message digest") = 5d0689ef49d2fae572b881b123a85ffa21595f36
|
||||
RIPEMD-160(hex: 616263) = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
|
||||
*/
|
||||
|
||||
/* Actual output:
|
||||
RIPEMD-160("") = 560e66de427fc2c3399e86c3e1d38c3c6017def2
|
||||
RIPEMD-160("abc") = 74266d6b4447493abb790c49e4bfa8f07263bcff
|
||||
RIPEMD-160("message digest") = 80ee01c69badb632393a9e05d1e7eebc2f05ac48
|
||||
RIPEMD-160(hex: 616263) = 74266d6b4447493abb790c49e4bfa8f07263bcff
|
||||
*/
|
||||
36
examples/crypto/ripemd160_example.fun
Executable file
36
examples/crypto/ripemd160_example.fun
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-01-02
|
||||
*/
|
||||
|
||||
// THIS IS BROKEN ACTUALLY! IT DOES NOT CALCULATE THE EXPECTED HASHES!
|
||||
|
||||
/*
|
||||
* Example: Using RIPEMD160 from lib/crypt/ripemd160.fun
|
||||
*
|
||||
* Known vectors:
|
||||
* - "" (empty) => 9c1185a5c5e9fc54612808977ee8f548b2258d31
|
||||
* - "abc" => 8eb208f7e05d987a9b04... (full known); we verify via hex of "abc"
|
||||
* - "The quick brown fox jumps over the lazy dog" => 37f332f68db77bd9d7edd4969571ad671cf9dd3b
|
||||
*/
|
||||
|
||||
#include <crypt/ripemd160.fun>
|
||||
|
||||
r = RIPEMD160()
|
||||
|
||||
// empty string
|
||||
print(r.ripemd160_str(""))
|
||||
|
||||
// "abc"
|
||||
print(r.ripemd160_hex("616263"))
|
||||
|
||||
// pangram
|
||||
print(r.ripemd160_str("The quick brown fox jumps over the lazy dog"))
|
||||
19
examples/crypto/ripemd160_test.fun
Executable file
19
examples/crypto/ripemd160_test.fun
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-12-27
|
||||
*/
|
||||
|
||||
#include <crypt/ripemd160.fun>
|
||||
print("Include OK")
|
||||
|
||||
/* Expected output:
|
||||
Include OK
|
||||
*/
|
||||
50
examples/crypto/sha1_demo.fun
Executable file
50
examples/crypto/sha1_demo.fun
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* SHA-1 usage demo
|
||||
*
|
||||
* Run without installing:
|
||||
* FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/sha1_demo.fun
|
||||
*/
|
||||
|
||||
#include <crypt/sha1.fun> as sha1
|
||||
|
||||
print("=== SHA-1 demo ===")
|
||||
|
||||
s = "abc"
|
||||
hex_abc = "616263" // "abc" in hex
|
||||
empty = ""
|
||||
|
||||
// Hash ASCII string directly
|
||||
d1 = sha1.SHA1().sha1_str(s)
|
||||
print("SHA-1('abc') = " + d1)
|
||||
|
||||
// Hash pre-encoded hex bytes
|
||||
d2 = sha1.SHA1().sha1_hex(hex_abc)
|
||||
print("SHA-1(616263 hex) = " + d2)
|
||||
|
||||
// Empty string
|
||||
d3 = sha1.SHA1().sha1_str(empty)
|
||||
print("SHA-1('') = " + d3)
|
||||
|
||||
print("=== done ===")
|
||||
|
||||
/* Expected output:
|
||||
=== SHA-1 demo ===
|
||||
SHA-1('abc') = e6cd2bcee460c45d41565ac877d866a159a16e19
|
||||
SHA-1(616263 hex) = e6cd2bcee460c45d41565ac877d866a159a16e19
|
||||
SHA-1('') = da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||
=== done ===
|
||||
*/
|
||||
|
||||
42
examples/crypto/sha256_demo.fun
Executable file
42
examples/crypto/sha256_demo.fun
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-09-29
|
||||
*/
|
||||
|
||||
// Include the pure Fun SHA-256 library
|
||||
include <crypt/sha256.fun>
|
||||
|
||||
sha = SHA256()
|
||||
|
||||
print("=== SHA-256 demo (hex input) ===")
|
||||
|
||||
// "" (empty)
|
||||
print(sha.sha256_hex("")) // -> e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
|
||||
// "abc"
|
||||
print(sha.sha256_hex("616263")) // -> ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
|
||||
|
||||
// "message digest"
|
||||
print(sha.sha256_hex("6d65737361676520646967657374")) // -> f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650
|
||||
|
||||
// "abcdefghijklmnopqrstuvwxyz"
|
||||
print(sha.sha256_hex("6162636465666768696a6b6c6d6e6f707172737475767778797a")) // -> 71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73
|
||||
|
||||
print("=== Done ===")
|
||||
|
||||
/* Expected output:
|
||||
=== SHA-256 demo (hex input) ===
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
3859a4ec00dcbed7c01d4a462d18c1f4097a690a1d4d459be4e5b6f5a594ee68
|
||||
de8ff7370090823795e96e3b7fbee3cfad374492417da99d72ba55297f7e58ab
|
||||
5d3ed26c5e75585f56e664c0ebc63aa185ec606109f6374fefa42c862670d257
|
||||
=== Done ===
|
||||
*/
|
||||
48
examples/crypto/sha256_str_demo.fun
Executable file
48
examples/crypto/sha256_str_demo.fun
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-09-29
|
||||
*/
|
||||
|
||||
// Demo: SHA-256 of raw strings (no hex decoding)
|
||||
include <crypt/sha256.fun>
|
||||
|
||||
sha = SHA256()
|
||||
|
||||
print("=== SHA-256 demo (raw string input via sha256_str) ===")
|
||||
|
||||
// "" (empty string)
|
||||
print(sha.sha256_str("")) // -> e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
|
||||
// "abc"
|
||||
print(sha.sha256_str("abc")) // -> 3859a4ec00dcbed7c01d4a462d18c1f4097a690a1d4d459be4e5b6f5a594ee68
|
||||
|
||||
// "616263" (the literal characters '6','1','6','2','6','3')
|
||||
print(sha.sha256_str("616263")) // -> faee5966a2c104cf2287085428a183fe58c18afdc5ff261571e8e9c4796ad635
|
||||
|
||||
// "message digest"
|
||||
print(sha.sha256_str("6d65737361676520646967657374")) // ->
|
||||
|
||||
// "abcdefghijklmnopqrstuvwxyz"
|
||||
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).
|
||||
*/
|
||||
35
examples/crypto/sha384_example.fun
Executable file
35
examples/crypto/sha384_example.fun
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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"))
|
||||
|
||||
/* Expected output:
|
||||
cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
|
||||
cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
|
||||
*/
|
||||
|
||||
43
examples/crypto/sha512_demo.fun
Executable file
43
examples/crypto/sha512_demo.fun
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-09-29
|
||||
*/
|
||||
|
||||
include <crypt/sha512.fun>
|
||||
|
||||
sha = SHA512()
|
||||
|
||||
print("=== SHA-512 demo (hex input) ===")
|
||||
|
||||
// "" (empty)
|
||||
print(sha.sha512_hex("")) // -> cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
||||
// 47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||
|
||||
// "abc"
|
||||
print(sha.sha512_hex("616263")) // -> ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a
|
||||
// 2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
||||
|
||||
// "message digest"
|
||||
print(sha.sha512_hex("6d65737361676520646967657374"))
|
||||
// -> 107dbf389d9e9f71a3a95f6c055b9251
|
||||
// bc5268c2be16d6c13492ea45b0199f33
|
||||
// 09e16455ab1e96118e8a905d5597b721
|
||||
// 3f36cc64dab6c0c5
|
||||
|
||||
print("=== Done ===")
|
||||
|
||||
/* Expected output:
|
||||
=== SHA-512 demo (hex input) ===
|
||||
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
||||
107dbf389d9e9f71a3a95f6c055b9251bc5268c2be16d6c13492ea45b0199f3309e16455ab1e96118e8a905d5597b72038ddb372a89826046de66687bb420e7c
|
||||
=== Done ===
|
||||
*/
|
||||
43
examples/crypto/sha512_str_demo.fun
Executable file
43
examples/crypto/sha512_str_demo.fun
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* 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-09-29
|
||||
*/
|
||||
|
||||
// Demo: SHA-512 of raw strings (no hex decoding)
|
||||
include <crypt/sha512.fun>
|
||||
|
||||
sha = SHA512()
|
||||
|
||||
print("=== SHA-512 demo (raw string input via sha512_str) ===")
|
||||
|
||||
// "" (empty string)
|
||||
print(sha.sha512_str("")) // -> cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce
|
||||
// 47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||
|
||||
// "abc"
|
||||
print(sha.sha512_str("abc")) // -> ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a
|
||||
// 2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
|
||||
|
||||
// "616263" (the literal characters '6','1','6','2','6','3')
|
||||
print(sha.sha512_str("616263")) // -> ee21095236a9c037f705f41ffa3cf60869891fcdb461c5c8fe50e5b1711a27b
|
||||
// fc02de2e387228651bdd034113cc59af777fdb9c915b70fdbed0eeacf7113296b
|
||||
|
||||
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).
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue