Replacing words inside text Topic is solved
Re: Replacing words inside text
I can't really debug a script fragment like this. Show your code.
Use Gosub to call another routine within your script.
My earlier comment about "retains..." meant that if you type a coded character pair that was not provided in the mapping, it will simply be included in the output string.
Use Gosub to call another routine within your script.
My earlier comment about "retains..." meant that if you type a coded character pair that was not provided in the mapping, it will simply be included in the output string.
Re: Replacing words inside text
@mikeyww, I don't have the final version of the script yet. It should look something like this:
Gosub, F3 displays the input field, but when I try to Send, ^v{Enter} to paste the previously copied encoded IP into the input field, nothing happens. Why?
Another problem arose. I specified in the map: = line all the values to be decoded:
But after saving the file and trying to reload the script, I get an error about a line with defined values: Error: Expression too long. What's wrong?
Code: Select all
#IfWinActive ahk_exe mirc.exe
^Tab::
Thread, NoTimers, True
KeyWait, Tab
Send, {F1}
Send, {Backspace 8}+{Left 8}^x^a{Backspace}
Gosub, F3
Send, ^v{Enter}
Send, ^a^x
SendInput, https://apps.db.ripe.net/db-web-ui/query?bflag=true&dflag=false&rflag=true&searchtext=&source=GRS
Send, {Left 11}^v^a^x
WinActivate ahk_exe chrome.exe
Send, ^t^v{Enter}
return
Another problem arose. I specified in the map: = line all the values to be decoded:
Code: Select all
map := {00: 0, 0x: 1, 02: 2, 03: 3, 04: 4, 0z: 5, 06: 6, 01: 7, 08: 8, 09: 9, 0B: 10, 0b: 11, 0c: 12, 0d: 13, 0e: 14, 0H: 15, x0: 16, xx: 17, x2: 18, x3: 19, x4: 20, xz: 21, x6: 22, x1: 23, x8: 24, x9: 25, xB: 26, xb: 27, xc: 28, xd: 29, xe: 30, xH: 31, 20: 32, 2x: 33, 22: 34, 23: 35, 24: 36, 2z: 37, 26: 38, 21: 39, 28: 40, 29: 41, 2B: 42, 2b: 43, 2c: 44, 2d: 45, 2e: 46, 2H: 47, 30: 48, 3x: 49, 32: 50, 33: 51, 34: 52, 3z: 53, 36: 54, 31: 55, 38: 56, 39: 57, 3B: 58, 3b: 59, 3c: 60, 3d: 61, 3e: 62, 3H: 63, 40: 64, 4x: 65, 42: 66, 43: 67, 44: 68, 4z: 69, 46: 70, 41: 71, 48: 72, 49: 73, 4B: 74, 4b: 75, 4c: 76, 4d: 77, 4e: 78, 4H: 79, z0: 80, zx: 81, z2: 82, z3: 83, z4: 84, zz: 85, z6: 86, z1: 87, z8: 88, z9: 89, zB: 90, zb: 91, zc: 92, zd: 93, ze: 94, zH: 95, 60: 96, 6x: 97, 62: 98, 63: 99, 64: 100, 6z: 101, 66: 102, 61: 103, 68: 104, 69: 105, 6B: 106, 6b: 107, 6c: 108, 6d: 109, 6e: 110, 6H: 111, 10: 112, 1x: 113, 12: 114, 13: 115, 14: 116, 1z: 117, 16: 118, 11: 119, 18: 120, 19: 121, 1B: 122, 1b: 123, 1c: 124, 1d: 125, 1e: 126, 1H: 127, 80: 128, 8x: 129, 82: 130, 83: 131, 84: 132, 8z: 133, 86: 134, 81: 135, 88: 136, 89: 137, 8B: 138, 8b: 139, 8c: 140, 8d: 141, 8e: 142, 8H: 143, 90: 144, 9x: 145, 92: 146, 93: 147, 94: 148, 9z: 149, 96: 150, 91: 151, 98: 152, 99: 153, 9B: 154, 9b: 155, 9c: 156, 9d: 157, 9e: 158, 9H: 159, B0: 160, Bx: 161, B2: 162, B3: 163, B4: 164, Bz: 165, B6: 166, B1: 167, B8: 168, B9: 169, BB: 170, Bb: 171, Bc: 172, Bd: 173, Be: 174, BH: 175, b0: 176, bx: 177, b2: 178, b3: 179, b4: 180, bz: 181, b6: 182, b1: 183, b8: 184, b9: 185, bB: 186, bb: 187, bc: 188, bd: 189, be: 190, bH: 191, c0: 192, cx: 193, c2: 194, c3: 195, c4: 196, cz: 197, c6: 198, c1: 199, c8: 200, c9: 201, cB: 202, cb: 203, cc: 204, cd: 205, ce: 206, cH: 207, d0: 208, dx: 209, d2: 210, d3: 211, d4: 212, dz: 213, d6: 214, d1: 215, d8: 216, d9: 217, dB: 218, db: 219, dc: 220, dd: 221, de: 222, dH: 223, e0: 224, ex: 225, e2: 226, e3: 227, e4: 228, ez: 229, e6: 230, e1: 231, e8: 232, e9: 233, eB: 234, eb: 235, ec: 236, ed: 237, ee: 238, eH: 239, H0: 240, Hx: 241, H2: 242, H3: 243, H4: 244, Hz: 245, H6: 246, H1: 247, H8: 248, H9: 249, HB: 250, Hb: 251, Hc: 252, Hd: 253, He: 254, HH: 255, xF: xxx}
Re: Replacing words inside text
My script does not refer to the Clipboard in any way. You are welcome to add that if you wish.
When you are ready to post your revised script, please provide it here.
When you are ready to post your revised script, please provide it here.
Re: Replacing words inside text
@mikeyww, unfortunately, I don't know how to paste the previously copied value into the input field of your script. I only thought of Send, ^v.
Re: Replacing words inside text
You wouldn't need to use a script to paste text into the script's own window like this. Perhaps you can back up and explain what you are trying to do, step by step. This will help to clarify so that we can reach resolution.
Re: Replacing words inside text
@mikeyww, OK…
First, I enter the nickname of the person whose IP address I want to decode into the IRC client text input field.
The F1 key runs an internal IRC client script that converts nickname to nick!ident@host. Here as an example: asdf!~z3040d4B@webczat.
From asdf!~z3040d4B@webczat all I need is an z3040d4B, so by pressing the Backspace key 8 times I get rid of @webczat. Then with +{Left 8}^x I select and cut z3040d4B. And with ^a{Backspace} I select and get rid of the rest of the text.
Here I would like to call the text input field for your script and paste the previously obtained z3040d4B into it and decode it.
Here, I select and cut the decoded form of the IP address.
Here I provide a link to the RIPE Database page which allows you to check which network the IP address belongs to.
In this way, I put the copied previously decoded IP address in the appropriate place of the link. In this way, I put the copied previously decoded IP address in the appropriate place of the link. I select the entire modified link and cut it out.
Here I activate the previously launched Chrome browser, open a new tab and paste the previously cut link and open a website.
I know it's a pretty twisted way, but I don't know the AutoHotkey scripting language enough to make it even simpler for myself, so I figured it out.
First, I enter the nickname of the person whose IP address I want to decode into the IRC client text input field.
Code: Select all
Send, {F1}
Code: Select all
Send, {Backspace 8}+{Left 8}^x^a{Backspace}
Code: Select all
Gosub, F3
Send, ^v{Enter}
Code: Select all
Send, ^a^x
Code: Select all
SendInput, https://apps.db.ripe.net/db-web-ui/query?bflag=true&dflag=false&rflag=true&searchtext=&source=GRS
Code: Select all
Send, {Left 11}^v^a^x
Code: Select all
WinActivate ahk_exe chrome.exe
Send, ^t^v{Enter}
I know it's a pretty twisted way, but I don't know the AutoHotkey scripting language enough to make it even simpler for myself, so I figured it out.
Re: Replacing words inside text
Example is below. Instead of sending backspace, etc., you can get the whole string and then the substring that you need. Instead of sending F3, you can decode the string using the script directly. See SubStr.
Code: Select all
F3::
InputBox, str, Decode, Enter the coded string.,, 300, 125
SendInput % ErrorLevel || str = "" ? "" : decode(str)
Return
F4::
Clipboard =
Send ^a^x
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else SendInput % "^t" decode(SubStr(Clipboard, -15, -8)) "`n"
Return
decode(str) {
Static map := {}, code := "
( LTrim Join
000x0203040z060108090B0b0c0d0e0Hx0xxx2x3x4xzx6x1x8x9xBxbxcxdxexH202x2223242z262128292B2b2c2d2e2H303
x3233343z363138393B3b3c3d3e3H404x4243444z464148494B4b4c4d4e4Hz0zxz2z3z4zzz6z1z8z9zBzbzczdzezH606x62
63646z666168696B6b6c6d6e6H101x1213141z161118191B1b1c1d1e1H808x8283848z868188898B8b8c8d8e8H909x92939
49z969198999B9b9c9d9e9HB0BxB2B3B4BzB6B1B8B9BBBbBcBdBeBHb0bxb2b3b4bzb6b1b8b9bBbbbcbdbebHc0cxc2c3c4cz
c6c1c8c9cBcbcccdcecHd0dxd2d3d4dzd6d1d8d9dBdbdcdddedHe0exe2e3e4eze6e1e8e9eBebecedeeeHH0HxH2H3H4HzH6H
1H8H9HBHbHcHdHeHH
)"
Loop, % !map.Count() * StrLen(code) / 2
map[SubStr(code, 2 * A_Index - 1, 2)] := A_Index - 1
Loop, % StrLen(str) / 2
new .= "." map[SubStr(str, 2 * A_Index - 1, 2)]
Return SubStr(new, 2)
}
Re: Replacing words inside text
Code: Select all
F4::
Clipboard =
Send ^a^x
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else SendInput % "^t" decode(SubStr(Clipboard, -15, -8)) "`n"
Return
decode(str) {
Static map := {}, code := "
( LTrim Join
000x0203040z060108090B0b0c0d0e0Hx0xxx2x3x4xzx6x1x8x9xBxbxcxdxexH202x2223242z262128292B2b2c2d2e2H303
x3233343z363138393B3b3c3d3e3H404x4243444z464148494B4b4c4d4e4Hz0zxz2z3z4zzz6z1z8z9zBzbzczdzezH606x62
63646z666168696B6b6c6d6e6H101x1213141z161118191B1b1c1d1e1H808x8283848z868188898B8b8c8d8e8H909x92939
49z969198999B9b9c9d9e9HB0BxB2B3B4BzB6B1B8B9BBBbBcBdBeBHb0bxb2b3b4bzb6b1b8b9bBbbbcbdbebHc0cxc2c3c4cz
c6c1c8c9cBcbcccdcecHd0dxd2d3d4dzd6d1d8d9dBdbdcdddedHe0exe2e3e4eze6e1e8e9eBebecedeeeHH0HxH2H3H4HzH6H
1H8H9HBHbHcHdHeHH
)"
Loop, % !map.Count() * StrLen(code) / 2
map[SubStr(code, 2 * A_Index - 1, 2)] := A_Index - 1
Loop, % StrLen(str) / 2
new .= "." map[SubStr(str, 2 * A_Index - 1, 2)]
Return SubStr(new, 2)
}
Re: Replacing words inside text
You can change the SendInput so that it instead assigns the Clipboard to the decoded string.
Re: Replacing words inside text
@mikeyww, I'm sorry, but I have no idea how to do it.
Re: Replacing words inside text
Below is an example that works with the sample string that you provided earlier.
Code: Select all
F4::
Clipboard =
Send ^a^c ; Example: om asdf!~z3040d4B@webczat
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else Clipboard := decode(SubStr(Clipboard, -15, -8)) ; Copied: 83.4.13.75
Return
decode(str) {
Static map := {}, code := "
( LTrim Join
000x0203040z060108090B0b0c0d0e0Hx0xxx2x3x4xzx6x1x8x9xBxbxcxdxexH202x2223242z262128292B2b2c2d2e2H303
x3233343z363138393B3b3c3d3e3H404x4243444z464148494B4b4c4d4e4Hz0zxz2z3z4zzz6z1z8z9zBzbzczdzezH606x62
63646z666168696B6b6c6d6e6H101x1213141z161118191B1b1c1d1e1H808x8283848z868188898B8b8c8d8e8H909x92939
49z969198999B9b9c9d9e9HB0BxB2B3B4BzB6B1B8B9BBBbBcBdBeBHb0bxb2b3b4bzb6b1b8b9bBbbbcbdbebHc0cxc2c3c4cz
c6c1c8c9cBcbcccdcecHd0dxd2d3d4dzd6d1d8d9dBdbdcdddedHe0exe2e3e4eze6e1e8e9eBebecedeeeHH0HxH2H3H4HzH6H
1H8H9HBHbHcHdHeHH
)"
Loop, % !map.Count() * StrLen(code) / 2
map[SubStr(code, 2 * A_Index - 1, 2)] := A_Index - 1
Loop, % StrLen(str) / 2
new .= "." map[SubStr(str, 2 * A_Index - 1, 2)]
Return SubStr(new, 2)
}
Re: Replacing words inside text
@mikeyww, it's ok now, but there's one problem. The decoding method used in this code isn't case-sensitive. And for example, B6 decodes as 182, while B6 is 166 and b6 is 182. Here I give the whole list in a more readable form:
https://pastebin.com/raw/P8cQtH2v
https://pastebin.com/raw/P8cQtH2v
Re: Replacing words inside text Topic is solved
You have raised a good point, which is a bug in my previous script, arising because array keys are not case-sensitive. The correction is below.
Code: Select all
test = b6B6
MsgBox, 64, Test of %test%, % decode(test)
F4::
Clipboard =
Send ^a^c ; Example: om asdf!~z3040d4B@webczat
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else Clipboard := decode(SubStr(Clipboard, -15, -8)) ; Copied: 83.4.13.74
Return
decode(str) {
Static code := " " "
( LTrim Join`s
00 0x 02 03 04 0z 06 01 08 09 0B 0b 0c 0d 0e 0H x0 xx x2 x3 x4 xz x6 x1 x8 x9 xB xb xc xd xe xH 20 2x
22 23 24 2z 26 21 28 29 2B 2b 2c 2d 2e 2H 30 3x 32 33 34 3z 36 31 38 39 3B 3b 3c 3d 3e 3H 40 4x 42 43
44 4z 46 41 48 49 4B 4b 4c 4d 4e 4H z0 zx z2 z3 z4 zz z6 z1 z8 z9 zB zb zc zd ze zH 60 6x 62 63 64 6z
66 61 68 69 6B 6b 6c 6d 6e 6H 10 1x 12 13 14 1z 16 11 18 19 1B 1b 1c 1d 1e 1H 80 8x 82 83 84 8z 86 81
88 89 8B 8b 8c 8d 8e 8H 90 9x 92 93 94 9z 96 91 98 99 9B 9b 9c 9d 9e 9H B0 Bx B2 B3 B4 Bz B6 B1 B8 B9
BB Bb Bc Bd Be BH b0 bx b2 b3 b4 bz b6 b1 b8 b9 bB bb bc bd be bH c0 cx c2 c3 c4 cz c6 c1 c8 c9 cB cb
cc cd ce cH d0 dx d2 d3 d4 dz d6 d1 d8 d9 dB db dc dd de dH e0 ex e2 e3 e4 ez e6 e1 e8 e9 eB eb ec ed
ee eH H0 Hx H2 H3 H4 Hz H6 H1 H8 H9 HB Hb Hc Hd He HH
)"
Loop, % StrLen(str) / 2
new .= "." Round((Instr(code, " " SubStr(str, 2 * A_Index - 1, 2), True) - 1) / 3)
Return SubStr(new, 2)
}
Re: Replacing words inside text
@mikeyww, now everything works fine. Thank you!
If possible, I would like to ask you for some script refinement. There are cases when the encoded form of the IP is longer or shorter than 8 characters or contains characters that aren't in the decryption key. Then it's impossible to decode the IP correctly. So I would like the script to copy the decryption result to the clipboard only if the retrieved string (between ! and @, omitting the ~ sign if present) is 8 characters long and contains the characters contained in the key I entered. Otherwise, the script should clear the clipboard.
If possible, I would like to ask you for some script refinement. There are cases when the encoded form of the IP is longer or shorter than 8 characters or contains characters that aren't in the decryption key. Then it's impossible to decode the IP correctly. So I would like the script to copy the decryption result to the clipboard only if the retrieved string (between ! and @, omitting the ~ sign if present) is 8 characters long and contains the characters contained in the key I entered. Otherwise, the script should clear the clipboard.
Re: Replacing words inside text
We have solved a few different problems here over the past couple of pages. I leave the next iteration to you. You have the tools here. You can use StrLen to check the string length. You can add conditional statements inside the function to determine whether matches are found. Best wishes.
Re: Replacing words inside text
OK, thanks once again.