Warcraft III resources & community, 2003–2006 · archived

CreateKey() A Checksum Generator

not rated
Submitted by Die_BackeCalculations0 downloads
This Script creates a checksum of a string. the string will be shortened, and every single letter has consequences for the created checksum (or KEY as i called it first).
e.g.
If you create a savecode, if the code is ready, you can add a key, and check the key again when loading the hero or whatever is saved. if then the key is missmatching, abord the loadtrigger. so, manipulating or hacking the savecode is harder.
the function has 3 parameters. the first is the string of which u want a checksum. the second is for the length of the key. type an integer here, that is SMALLER than the stringlength of the first parameter. the last parameter contains a charmap. its a list of letters, numbers and other symbols, and has to contain every symbol ONCE that the first parameter can contain.

IMPORTANT!! NEEDS THE IndexOfSubstring() FUNCTION!

Source

//------------------..Code for taking 2 strings together..----------------
function StringFusion takes string s1, string s2, string alphabet returns string
    local string s = ""
    local string zero = SubStringBJ(alphabet, 1, 1)
    local integer length = 0
    local integer char = 0
    if ( StringLength(s1) < StringLength(s2) ) then
        loop
            exitwhen StringLength(s1) == StringLength(s2)
            set s1 = zero + s1
        endloop
    endif
    if ( StringLength(s2) < StringLength(s1) ) then
        loop
            exitwhen StringLength(s2) == StringLength(s1)
            set s2 = zero + s2
        endloop
    endif
    set length = StringLength(s1)
    loop
        exitwhen StringLength(s) == length
        set char = ModuloInteger(IndexOfSubstring(alphabet, SubStringBJ(s1, 1, 1)) + IndexOfSubstring(alphabet, SubStringBJ(s2, 1, 1)), StringLength(alphabet)) + 1
        set s = s + SubStringBJ(alphabet, char, char)
        set s1 = SubStringBJ(s1, 2, StringLength(s1))
        set s2 = SubStringBJ(s2, 2, StringLength(s2))
    endloop
    return s
endfunction
//-------------------..Code for creating the hero-key..-------------------
function CreateKey takes string source, integer keylength, string alphabet returns string
    local string key = ""
    if ( keylength == 0 ) then
        return ""
    endif
    if ( StringLength(source) == keylength ) then
        return source
    elseif ( StringLength(source) <= 2 * keylength ) then
        return StringFusion(SubStringBJ(source, 1, keylength), SubStringBJ(source, keylength + 1, StringLength(source)), alphabet)
    endif
    return CreateKey(StringFusion(SubStringBJ(source, 1, keylength), SubStringBJ(source, keylength + 1, 2 * keylength), alphabet) + SubStringBJ(source, 2 * keylength + 1, StringLength(source)), keylength, alphabet)
endfunction

Comments

0

No comments.