| 827 | == FoxPro == |
| 828 | {{{ |
| 829 | PARAMETERS cfile |
| 830 | PRIVATE ALL |
| 831 | |
| 832 | ******* |
| 833 | * enviroment setup |
| 834 | ******* |
| 835 | cret='' |
| 836 | glTalk=(SET("TALK")="ON") |
| 837 | |
| 838 | IF vartype(cfile)<>'C' |
| 839 | cfile='breakdance.avi' |
| 840 | ENDIF |
| 841 | |
| 842 | |
| 843 | |
| 844 | IF glTalk |
| 845 | ? cfile |
| 846 | ? cfile='' |
| 847 | ? LEN(cfile) |
| 848 | endif |
| 849 | |
| 850 | |
| 851 | nfile=FOPEN(cfile) |
| 852 | nsize=FSEEK(nfile,0,2) |
| 853 | |
| 854 | IF gltalk |
| 855 | ? cfile |
| 856 | ? 'size?>' |
| 857 | ?? nsize |
| 858 | endif |
| 859 | FSEEK(nfile,0,0) |
| 860 | |
| 861 | ****** |
| 862 | * length reencode to 64 uint |
| 863 | ***** |
| 864 | chash=hashsize(nsize) |
| 865 | cempty=chr(0) |
| 866 | cret='' |
| 867 | IF LEN(chash)<8 |
| 868 | FOR i=1 TO 8-LEN(chash) |
| 869 | cret=cret+cempty |
| 870 | ENDFOR |
| 871 | ENDIF |
| 872 | cret=cret+chash |
| 873 | nSum=0 |
| 874 | |
| 875 | ******* |
| 876 | * first 64kb |
| 877 | ****** |
| 878 | |
| 879 | |
| 880 | FOR i=1 TO 8192 |
| 881 | cpom=FREAD(nfile,8) |
| 882 | cpom=reverse(cpom) |
| 883 | nSum=nSum+LEN(cpom) |
| 884 | IF gltalk |
| 885 | do buildhex WITH cret |
| 886 | ?? '+' |
| 887 | DO buildhex WITH cpom |
| 888 | ? '=' |
| 889 | ENDIF |
| 890 | cret=adint64(cret,cpom) |
| 891 | ENDFOR |
| 892 | |
| 893 | ******* |
| 894 | * last 64kb |
| 895 | ******* |
| 896 | |
| 897 | FSEEK(nfile,-65536,2) |
| 898 | FOR i=1 TO 8192 |
| 899 | cpom=FREAD(nfile,8) |
| 900 | cpom=reverse(cpom) |
| 901 | cret=adint64(cret,cpom) |
| 902 | nSum=nSum+LEN(cpom) |
| 903 | ENDFOR |
| 904 | FCLOSE(nfile) |
| 905 | |
| 906 | **** |
| 907 | * build hexa |
| 908 | **** |
| 909 | IF gltalk |
| 910 | |
| 911 | DO buildhex WITH cret |
| 912 | ? |
| 913 | ? 'Spocital som' |
| 914 | ?? nSum |
| 915 | ENDIF |
| 916 | RETURN buildhex(cret) |
| 917 | |
| 918 | FUNCTION reverse |
| 919 | PARAMETERS cstring |
| 920 | PRIVATE ALL |
| 921 | cret='' |
| 922 | FOR i=1 TO LEN(cstring) |
| 923 | cret=cret+SUBSTR(cstring,LEN(cstring)-i+1,1) |
| 924 | ENDFOR |
| 925 | RETURN cret |
| 926 | |
| 927 | FUNCTION buildhex |
| 928 | PARAMETERS cstring,lkam |
| 929 | PRIVATE ALL |
| 930 | gcTalk=SET("TALK") |
| 931 | cret='' |
| 932 | FOR i=1 TO LEN(cstring) |
| 933 | cpom=dec2basx(ASC(SUBSTR(cstring,i,1)),16) |
| 934 | IF LEN(cpom)<2 |
| 935 | cout='0'+cpom |
| 936 | cpom=cout |
| 937 | ENDIF |
| 938 | |
| 939 | cret=cret+cpom |
| 940 | IF gcTALK="ON" |
| 941 | ?? cpom |
| 942 | ?? ':' |
| 943 | ENDIF |
| 944 | ENDFOR |
| 945 | RETURN cret |
| 946 | |
| 947 | FUNCTION adint64 |
| 948 | PARAMETERS cstring1,cstring2 |
| 949 | PRIVATE ALL |
| 950 | DIMENSION car (8,1) as Character |
| 951 | |
| 952 | *** |
| 953 | * 8 bytes both |
| 954 | *** |
| 955 | nincrement=0 |
| 956 | cret='' |
| 957 | FOR i=8 TO 1 STEP -1 |
| 958 | nfir=ASC(SUBSTR(cstring1,i,1)) |
| 959 | nsec=ASC(SUBSTR(cstring2,i,1)) |
| 960 | nout=nincrement+nfir+nsec |
| 961 | IF nout>255 |
| 962 | nincrement=INT(nout/256) |
| 963 | nout=nout-(nincrement*256) |
| 964 | ELSE |
| 965 | nincrement=0 |
| 966 | ENDIF |
| 967 | car(i)=CHR(nout) |
| 968 | ENDFOR |
| 969 | FOR i=1 TO 8 |
| 970 | cret=cret+car(i) |
| 971 | ENDFOR |
| 972 | RETURN cret |
| 973 | |
| 974 | |
| 975 | FUNCTION hashsize |
| 976 | |
| 977 | PARAMETERS ncislo |
| 978 | PRIVATE ALL |
| 979 | cret='' |
| 980 | creverse='' |
| 981 | DO WHILE .t. |
| 982 | npom=INT(ncislo/256) |
| 983 | npom2=ncislo-npom*256 |
| 984 | creverse=creverse+CHR(npom2) |
| 985 | ncislo=npom |
| 986 | IF ncislo=0 |
| 987 | EXIT |
| 988 | ENDIF |
| 989 | ENDDO |
| 990 | FOR i=1 TO LEN(creverse) |
| 991 | cret=cret+SUBSTR(creverse,LEN(creverse)-i+1,1) |
| 992 | ENDFOR |
| 993 | RETURN cret |
| 994 | |
| 995 | |
| 996 | *.............................................................................. |
| 997 | * Function: DEC2BASX |
| 998 | * Purpose: Convert whole number 0-?, to base 2-16 |
| 999 | * |
| 1000 | * Parameters: nTempNum - number to convert (0-9007199254740992) |
| 1001 | * base - base to convert to i.e., 2 4 8 16... |
| 1002 | * returns: string |
| 1003 | * Usage: cresult=Dec2BasX(nParm1, nParm2) |
| 1004 | * STORE Dec2BasX(255, 16) TO cMyString &&... cMyString contains 'ff' |
| 1005 | *.............................................................................. |
| 1006 | FUNCTION dec2basx |
| 1007 | PARAMETERS nTempNum, nNewBase |
| 1008 | |
| 1009 | STORE 0 TO nWorkVal,; |
| 1010 | remainder,; |
| 1011 | dividend,; |
| 1012 | nextnum,; |
| 1013 | digit |
| 1014 | |
| 1015 | nWorkVal = nTempNum |
| 1016 | ret_str = '' |
| 1017 | |
| 1018 | DO WHILE .T. |
| 1019 | digit = MOD(nWorkVal, nNewBase) |
| 1020 | dividend = nWorkVal / nNewBase |
| 1021 | nWorkVal = INT(dividend) |
| 1022 | |
| 1023 | DO CASE |
| 1024 | CASE digit = 10 |
| 1025 | ret_str = 'a' + ret_str |
| 1026 | CASE digit = 11 |
| 1027 | ret_str = 'b' + ret_str |
| 1028 | CASE digit = 12 |
| 1029 | ret_str = 'c' + ret_str |
| 1030 | CASE digit = 13 |
| 1031 | ret_str = 'd' + ret_str |
| 1032 | CASE digit = 14 |
| 1033 | ret_str = 'e' + ret_str |
| 1034 | CASE digit = 15 |
| 1035 | ret_str = 'f' + ret_str |
| 1036 | OTHERWISE |
| 1037 | ret_str = LTRIM(STR(digit)) + ret_str |
| 1038 | ENDCASE |
| 1039 | |
| 1040 | IF nWorkVal = 0 |
| 1041 | EXIT |
| 1042 | ENDIF ( nWorkVal = 0 ) |
| 1043 | ENDDO ( .T. ) |
| 1044 | RETURN ret_str |
| 1045 | }}} |
| 1046 | |