Convert API key to string of numbers and vice versa in ActionScripts3

We need to convert some API KEYS to line numbers and convert them to the original string.

Sample API KEY: "ZfIgG9LliwY4cDw4Rqso0m7SEQZovI"

We converted it using our algorithm

var encode_array:Array = "ZfIgG9LliwY4cDw4Rqso0m7SEQZovI".split("");
var encode_string:String;
var count1:int = encode_array.length; var i1:int;
for (i1 = 0; i1 < count1; i1++) 
{ 

    switch(encode_array[i1]) 
   { 
    case "*": 
        encode_string += *;
        break; 
    ...
   }

Converted API KEY:"364219431799224845593594391459942853555190499729152736515819"

Each number 2 on this line refers to 1 chracter in the KEY API. (Example: "36"> "Z")

My problem is the second part to undo this (convert every 2 numbers to a specific character). How can I divide all 2 numbers on this line and store them in an array? I think this is possible using Split " or RegExp in ActionScripts, but I don't know how to do this.

+4
source share
1 answer

There is an easy way:

        var s:String = '364219431799224845593594391459942853555190499729152736515819';
        for (var i:int = 0; i < s.length; i += 2) {
            var sub:String = s.charAt(i) + s.charAt(i + 1);
            trace(sub);//convert 
        }
+2
source

Source: https://habr.com/ru/post/1667960/


All Articles