forth.frt 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. : HELLO ( -- ) CR ." Hello, world!" ;
  2. HELLO <cr>
  3. Hello, world!
  4. : [CHAR] CHAR POSTPONE LITERAL ; IMMEDIATE
  5. 0 value ii 0 value jj
  6. 0 value KeyAddr 0 value KeyLen
  7. create SArray 256 allot \ state array of 256 bytes
  8. : KeyArray KeyLen mod KeyAddr ;
  9. : get_byte + c@ ;
  10. : set_byte + c! ;
  11. : as_byte 255 and ;
  12. : reset_ij 0 TO ii 0 TO jj ;
  13. : i_update 1 + as_byte TO ii ;
  14. : j_update ii SArray get_byte + as_byte TO jj ;
  15. : swap_s_ij
  16. jj SArray get_byte
  17. ii SArray get_byte jj SArray set_byte
  18. ii SArray set_byte
  19. ;
  20. : rc4_init ( KeyAddr KeyLen -- )
  21. 256 min TO KeyLen TO KeyAddr
  22. 256 0 DO i i SArray set_byte LOOP
  23. reset_ij
  24. BEGIN
  25. ii KeyArray get_byte jj + j_update
  26. swap_s_ij
  27. ii 255 < WHILE
  28. ii i_update
  29. REPEAT
  30. reset_ij
  31. ;
  32. : rc4_byte
  33. ii i_update jj j_update
  34. swap_s_ij
  35. ii SArray get_byte jj SArray get_byte + as_byte SArray get_byte xor
  36. ;