Dictionaries in AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GameNtt
Posts: 154
Joined: 19 Aug 2022, 03:36

Dictionaries in AHK

Post by GameNtt » 30 Nov 2022, 07:49

A while back, I had asked on reddit for a conversion function from ASCII to Binary. In the comments, someone had given me a function with code for a "dictionary" way. I was going back to try and understand how it works, but I ultimately got confused. Could anyone help me understand how the "dictionary" works?

Code: Select all

    static dic := {"00100000":" ", "00100001":"!", "00100010":"""", "00100011":"#", "00100100":"$", "00100101":"%", "00100110":"&", "00100111":"'", "00101000":"(", "00101001":")", "00101010":"*", "00101011":"+", "00101100":",", "00101101":"-", "00101110":".", "00101111":"/", "00110000":"0", "00110001":"1", "00110010":"2", "00110011":"3", "00110100":"4", "00110101":"5", "00110110":"6", "00110111":"7", "00111000":"8", "00111001":"9", "00111010":":", "00111011":";", "00111100":"<", "00111101":"=", "00111110":">", "00111111":"?", "01000000":"@", "01000001":"A", "01000010":"B", "01000011":"C", "01000100":"D", "01000101":"E", "01000110":"F", "01000111":"G", "01001000":"H", "01001001":"I", "01001010":"J", "01001011":"K", "01001100":"L", "01001101":"M", "01001110":"N", "01001111":"O", "01010000":"P", "01010001":"Q", "01010010":"R", "01010011":"S", "01010100":"T", "01010101":"U", "01010110":"V", "01010111":"W", "01011000":"X", "01011001":"Y", "01011010":"Z", "01011011":"[", "01011100":"\", "01011101":"]", "01011110":"^", "01011111":"_", "01100000":"``", "01100001":"a", "01100010":"b", "01100011":"c", "01100100":"d", "01100101":"e", "01100110":"f", "01100111":"g", "01101000":"h", "01101001":"i", "01101010":"j", "01101011":"k", "01101100":"l", "01101101":"m", "01101110":"n", "01101111":"o", "01110000":"p", "01110001":"q", "01110010":"r", "01110011":"s", "01110100":"t", "01110101":"u", "01110110":"v", "01110111":"w", "01111000":"x", "01111001":"y", "01111010":"z", "01111011":"{", "01111100":"|", "01111101":"}", "01111110":"~"}
    static dic := (_:= [],_.InsertAt(32, "00100000", "00100001", "00100010", "00100011", "00100100", "00100101", "00100110", "00100111", "00101000", "00101001", "00101010", "00101011", "00101100", "00101101", "00101110", "00101111", "00110000", "00110001", "00110010", "00110011", "00110100", "00110101", "00110110", "00110111", "00111000", "00111001", "00111010", "00111011", "00111100", "00111101", "00111110", "00111111", "01000000", "01000001", "01000010", "01000011", "01000100", "01000101", "01000110", "01000111", "01001000", "01001001", "01001010", "01001011", "01001100", "01001101", "01001110", "01001111", "01010000", "01010001", "01010010", "01010011", "01010100", "01010101", "01010110", "01010111", "01011000", "01011001", "01011010", "01011011", "01011100", "01011101", "01011110", "01011111", "01100000", "01100001", "01100010", "01100011", "01100100", "01100101", "01100110", "01100111", "01101000", "01101001", "01101010", "01101011", "01101100", "01101101", "01101110", "01101111", "01110000", "01110001", "01110010", "01110011", "01110100", "01110101", "01110110", "01110111", "01111000", "01111001", "01111010", "01111011", "01111100", "01111101", "00100000", "00100001", "00100010", "00100011", "00100100", "00100101", "00100110", "00100111", "00101000", "00101001", "00101010", "00101011", "00101100", "00101101", "00101110", "00101111", "00110000", "00110001", "00110010", "00110011", "00110100", "00110101", "00110110", "00110111", "00111000", "00111001", "00111010", "00111011", "00111100", "00111101", "00111110", "00111111", "01000000", "01000001", "01000010", "01000011", "01000100", "01000101", "01000110", "01000111", "01001000", "01001001", "01001010", "01001011", "01001100", "01001101", "01001110", "01001111", "01010000", "01010001", "01010010", "01010011", "01010100", "01010101", "01010110", "01010111", "01011000", "01011001", "01011010", "01011011", "01011100", "01011101", "01011110", "01011111", "01100000", "01100001", "01100010", "01100011", "01100100", "01100101", "01100110", "01100111", "01101000", "01101001", "01101010", "01101011", "01101100", "01101101", "01101110", "01101111", "01110000", "01110001", "01110010", "01110011", "01110100", "01110101", "01110110", "01110111", "01111000", "01111001", "01111010", "01111011", "01111100", "01111101", "01111110"))

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Dictionaries in AHK

Post by mikeyww » 30 Nov 2022, 07:55

An associative array can be used to support a "lookup" functionality. One "looks up" a value associated with another value (called the key).

Code: Select all

dic := {"00100000": " ", "00100001": "!"}
MsgBox, % dic["00100001"]
Explained: Associative arrays

GameNtt
Posts: 154
Joined: 19 Aug 2022, 03:36

Re: Dictionaries in AHK

Post by GameNtt » 30 Nov 2022, 11:13

When this is run, why does the encoding (b64rencdic) not take the input as capital letter? The return value gives me the value corresponding to the input's lowercase equivalent.

Code: Select all

b64rdecdic:= {"000000": "A", "000001": "B", "000010": "C", "000011": "D", "000100": "E", "000101": "F", "000110": "G", "000111": "H", "001000": "I", "001001": "J", "001010": "K", "001011": "L", "001100": "M", "001101": "N", "001110": "O", "001111": "P", "010000": "Q", "010001": "R", "010010": "S", "010011": "T", "010100": "U", "010101": "V", "010110": "W", "010111": "X", "011000": "Y", "011001": "Z", "011010": "a", "011011": "b", "011100": "c", "011101": "d", "011110": "e", "011111": "f", "100000": "g", "100001": "h", "100010": "i", "100011": "j", "100100": "k", "100101": "l", "100110": "m", "100111": "n", "101000": "o", "101001": "p", "101010": "q", "101011": "r", "101100": "s", "101101": "t", "101110": "u", "101111": "v", "110000": "w", "110001": "x", "110010": "y", "110011": "z", "110100": "0", "110101": "1", "110110": "2", "110111": "3", "111000": "4", "111001": "5", "111010": "6", "111011": "7", "111100": "8", "111101": "9", "111110": "+", "111111": "/"}
b64rencdic:= {"A": "000000", "B": "000001", "C": "000010", "D": "000011", "E": "000100", "F": "000101", "G": "000110", "H": "000111", "I": "001000", "J": "001001", "K": "001010", "L": "001011", "M": "001100", "N": "001101", "O": "001110", "P": "001111", "Q": "010000", "R": "010001", "S": "010010", "T": "010011", "U": "010100", "V": "010101", "W": "010110", "X": "010111", "Y": "011000", "Z": "011001", "a": "011010", "b": "011011", "c": "011100", "d": "011101", "e": "011110", "f": "011111", "g": "100000", "h": "100001", "i": "100010", "j": "100011", "k": "100100", "l": "100101", "m": "100110", "n": "100111", "o": "101000", "p": "101001", "q": "101010", "r": "101011", "s": "101100", "t": "101101", "u": "101110", "v": "101111", "w": "110000", "x": "110001", "y": "110010", "z": "110011", "0": "110100", "1": "110101", "2": "110110", "3": "110111", "4": "111000", "5": "111001", "6": "111010", "7": "111011", "8": "111100", "9": "111101", "+": "111110", "/": "111111"}
OutputDebug, % b64rdecdic["000011"] " " b64rencdic["Z"]


Post Reply

Return to “Ask for Help (v1)”