PARAMETERS retizek
seminko = "0123456789ABCDEF"

RETURN chrtohex(s_h_a_1(m.retizek))


**********************************************************************************
**********************************************************************************

FUNCTION s_h_a_1 (pcStringIn)
  LOCAL lcIn, i, j, l, T, H0, H1, H2, H3, H4, A, B, C, D, E
  LOCAL ARRAY W(80)

  l = MOD(LEN(pcStringIn)+1+8,64)
  lcIn = pcStringIn + ;
    CHR(0x80) + ;
    REPLICATE(CHR(0x00), 64-MOD(LEN(pcStringIn)+1+8,64))+;
    NumToBin (8*LEN(pcStringIn), 8)

  H0 = 0x67452301
  H1 = 0xEFCDAB89
  H2 = 0x98BADCFE
  H3 = 0x10325476
  H4 = 0xC3D2E1F0

  FOR i = 1 TO LEN(lcIn)-64+1 STEP 64
    FOR T=0 TO 15
      W(T+1) = ;
        256*256*256*ASC(SUBSTR(lcIn,i+4*T+0,1))+;
            256*256*ASC(SUBSTR(lcIn,i+4*T+1,1))+;
                256*ASC(SUBSTR(lcIn,i+4*T+2,1))+;
                    ASC(SUBSTR(lcIn,i+4*T+3,1))
    ENDFOR

    FOR T = 16 TO 79
      W(T+1) = Sn(1, BITXOR(BITXOR(BITXOR(W(T+1-3),W(T+1-8)),W(T+1-14)),W(T+1-16)))
    ENDFOR
    A = H0
    B = H1
    C = H2
    D = H3
    E = H4
    FOR T = 0 TO 79
      TEMP = Sn(5,A) + F(T,B,C,D) + E + W(T+1) + K(T)
      E = D
      D = C
      C = Sn(30,B)
      B = A
      A = TEMP

    ENDFOR
    H0 = H0 + A
    H1 = H1 + B
    H2 = H2 + C
    H3 = H3 + D
    H4 = H4 + E
  ENDFOR
  RETURN ;
    NumToBin(H0,4)+;
    NumToBin(H1,4)+;
    NumToBin(H2,4)+;
    NumToBin(H3,4)+;
    NumToBin(H4,4)

FUNCTION Sn(N, X)
  RETURN BITOR(BITLSHIFT(X,N), BITRSHIFT(X,32-N))

FUNCTION F(T,B,C,D)

  DO CASE
  CASE BETW(T,  0, 19)
    RETURN BITOR(BITAND(B,C),BITAND(BITNOT(B),D))
  CASE BETWEEN(T, 20, 39)
    RETURN BITXOR(BITXOR(B,C),D)
  CASE BETWEEN(T, 40, 59)
    RETURN BITOR(BITOR(BITAND(B,C),BITAND(B,D)),BITAND(C,D))
  CASE BETWEEN(T, 60, 79)
    RETURN BITXOR(BITXOR(B,C),D)
  ENDCASE

FUNCTION K(T)

  DO CASE
  CASE BETWEEN(T,  0, 19)
    RETURN 0x5A827999
  CASE BETWEEN(T, 20, 39)
    RETURN 0x6ED9EBA1
  CASE BETWEEN(T, 40, 59)
    RETURN 0x8F1BBCDC
  CASE BETWEEN(T, 60, 79)
    RETURN 0xCA62C1D6
  ENDCASE

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
FUNCTION NumToBin (pnNumber, pnNoOfBytes)
  LOCAL Num, i, ret
  ret = ""
  Num = pnNumber
  IF Num<0
    Num = Num+0xFFFFFFFF+1
  ENDIF
  FOR i = 1 TO pnNoOfBytes
    ret = CHR(MOD(Num,256))+ret
    Num = INT(Num/256)
  ENDFOR
  RETURN ret

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
FUNCTION CHRTOHEX (pcString)
LOCAL i, N, ret
ret = ""
FOR i = 1 TO LEN(pcString)
    N = ASC(SUBSTR(pcString,i,1))
    ret = ret + ;
        SUBSTR(m.seminko,INT(N/16)+1,1) + ;
        SUBSTR(m.seminko,MOD(N,16)+1,1)
ENDFOR
RETURN ret
