Extra functions for ease in Cryptography-adjacent scripts (like mine)

Propose new features and changes
GameNtt
Posts: 154
Joined: 19 Aug 2022, 03:36

Extra functions for ease in Cryptography-adjacent scripts (like mine)

26 Dec 2022, 00:22

1) Another modulus function or an overhaul to the current modulus function : Currently, negative numbers in either the divisor or the dividend do not give an intended result/ work in the mathematically intended way. It wouldn't be that hard to change the current function or implement another function for it to work in the mathematical way, I guess.

2)Two-Way Associative Arrays : It would be massively helpful if we had Two-Way Associative Arrays which would mean that in an array Arr := {"A":"0123","B":"0124"...},
Arr["A"] would give "0123" (which Associative Arrays does currently) and Arr["0123"] would give "A" (which Associative Arrays does not do currently).

3)Using values of Variables for getting values of array items : Associative Arrays are basically the same thing as Simple Arrays, the only difference is that you can use Variables to get the values that correspond to the "key" in associative arrays, while in Simple Arrays, the "key" (the distinguisher? that comes after the name of the array and fullstop (example : In arr.1 , 1 is the "key"/distinguisher)) can only be the actual "key" and not a variable.

4)CaseSensitive Associative Arrays : You could do it with Scripting.Dictionary but that way you have to either use a custom function to add multiple key-value pairs in one line or you have to use one line for one pair. I do not know what the problems/issues would be in trying to add CaseSensitive Associative Arrays but it just would be convenient.

5) Additional (native) function to add multiple key-value pairs at a time in Scripting.Dictionary Arrays : Currently you have to use a custom function in order to add multiple pairs at once to Scripting.Dictionary associative arrays. It just would be convenient to add multiple pairs in one line rather than having to use x number of lines for x pairs.
Last edited by GameNtt on 26 Dec 2022, 04:45, edited 1 time in total.
lexikos
Posts: 9643
Joined: 30 Sep 2013, 04:07
Contact:

Re: Extra functions for ease in Cryptography-adjacent scripts (like mine)

26 Dec 2022, 03:50

There are multiple clues in your post that you are using AutoHotkey v1.1. Please note:
  • v2.0 already has case-sensitive associative arrays.
  • v2.0 already has a method for setting multiple key-value pairs in an associative array.
  • v1.1 development is basically dying a slow death. I am basically not adding new features to it, especially in areas that have already been superseded by v2.0, such as objects.
Regarding modulo, intent varies. AutoHotkey uses the native C++ modulo operator for integers and either the C runtime fmod or qmathFmod for floating-point numbers. I don't care enough to second-guess the language designers of C++. I probably won't care enough to understand the purported problem unless I encounter it myself. If someone submits a pull request with an alternative function (not changing the established behaviour of the existing function), demonstration of the difference in result, and evidence supporting the "correctness", I might accept it.

A "two-way" associative array would just be an object containing two associative arrays. It is trivial to create such an object in script, especially in v2 (by overriding the __Item property), or to simply use two associative arrays.

You appear to have a mistaken idea about "Simple Arrays" and "Associative Arrays", which are terms that I'm guessing you picked up from the documentation. They are not different types of objects in v1 (and this is explicitly stated in the "Associative Arrays" section of the documentation). The terms are just used to describe how you will use the object. The "Simple Arrays" section of the documentation demonstrates using a variable for the key/index in a simple array. It doesn't even demonstrate the (much less typical) arr.1 syntax you mention as a means of getting array elements.

It would make no sense to add a built-in function for extending the functionality or syntax of an external library (Scripting.Dictionary).

Please consider using line breaks and/or list bbcode (as I've done) to improve the readability of your posts in future.
GameNtt
Posts: 154
Joined: 19 Aug 2022, 03:36

Re: Extra functions for ease in Cryptography-adjacent scripts (like mine)

26 Dec 2022, 06:28

About the modulo function, there is a ten-year old topic viewtopic.php?f=14&t=428 which discusses the same modulo function and in the last post, I had added a function for dealing with the negative number in the first parameter. To do it in the second parameter xor could be used.
iPhilip
Posts: 827
Joined: 02 Oct 2013, 12:21

Re: Extra functions for ease in Cryptography-adjacent scripts (like mine)

12 Jan 2023, 13:33

The idea of a "two-way" associative array intrigued me so I looked into it.

Here's an AutoHotkey v1 implementation. Notice that the array keys are case-insensitive.

Code: Select all

#Requires AutoHotkey v1.1.33+

class twa {
   __new() {
      this._ := {}
   }
   __get(key) {
      if (key != "_")
         return this._[key]
   }
   __set(key, value) {
      if (key != "_")
         return (this._[key] := value, this._[value] := key)
   }
}

m := new twa()
m.a := Ord("a")  ; 97
m.A := Ord("A")  ; 65
MsgBox % m.a " " m[Ord("a")]  ; 65 a
MsgBox % m.A " " m[Ord("A")]  ; 65 A
MsgBox % m.B  ; Blank
The AutoHotkey v2 implementation is surprisingly simple. :)

Code: Select all

#Requires AutoHotkey v2.0+

class twa extends map {
   ; CaseSense := false  ; Uncomment this to make the keys case-insensitive.
	__item[key] {
		set => (super[value] := key, super[key] := value)
	}
}

m := twa()
m['a'] := Ord('a')  ; 97
m['A'] := Ord('A')  ; 65
MsgBox m['a'] ' ' m[Ord('a')]  ; 97 a
MsgBox m['A'] ' ' m[Ord('A')]  ; 65 A
MsgBox m['B']  ; Error
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
iPhilip
Posts: 827
Joined: 02 Oct 2013, 12:21

Re: Extra functions for ease in Cryptography-adjacent scripts (like mine)

16 Jan 2023, 16:15

If you decided that you wanted all Maps to be two-way, you could do it this way:

Code: Select all

#Requires AutoHotkey v2.0+

SetMapsTwoWay() {
   Set := Map.Prototype.GetOwnPropDesc('__Item').Set
   Map.Prototype.DefineProp('__Item', {Set:(this, value, key) => (Set(this, key, value), Set(this, value, key))})
}

SetMapsTwoWay()
m := Map()
m['a'] := Ord('a')  ; 97
m['A'] := Ord('A')  ; 65
MsgBox m['a'] ' ' m[Ord('a')]  ; 97 a
MsgBox m['A'] ' ' m[Ord('A')]  ; 65 A
MsgBox m['B']  ; Error
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 8 guests