I need help writing a script for batch.
I forgot the password for a file, it's a simple password 4 chars ( 1234, asdf, qwer) .
The command line is this:
C:\Users\DB> .\open.exe --file=db1.bin --password=asdf
Logging to C:\Users\DB\open.log
Error: failed to load: invalid password
I managed to generate a list of passwords (pass.txt) since the number is either 1st or last in string and only lower case but still there are couple thousands. Is there any way to automate this?
To iterate over a text file, use a for /f loop.
for /f %%A in (pass.txt) do open.exe --file=db1.bin --password=%%A
If you want it to track where you are in the file, add an echo.
for /f %%A in (pass.txt) do (
echo Now trying %%A
open.exe --file=db1.bin --password=%%A
)
#echo off
(
for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for %%b in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for %%c in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for %%d in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
echo(%%a%%b%%c%%d
)
)
)
)
)>pass.txt
needs about half a minute to generate all possible 808496 passwords
{letter | number}{letter}{letter}{letter | number}
where only start OR end may be a number). If both start AND end could be a number, just skip the last two lines (876096 passwords)
Related
A B C D
E F G H
I J K L
M N O P
If I chose to join the columns I would ={A1:A;B1:B;C1:C;D1:D} but it would look like this:
A
E
I
M
B
F
J
N
... and so on
I would like it to look like this:
A
B
C
D
E
F
G
... and so on
How to proceed in this case?
Note: It may happen that some of the columns are not complete in data, some may have more values than the others, but I still want to continue following this same pattern. Example:
A B D
E G H
I J K L
M N O P
Result:
A
B
D
E
G
H
... and so on
use:
=TRANSPOSE(QUERY(TRANSPOSE(A:D),, 9^9))
then:
=TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A:D),,9^9)),,9^9), " "))
I want to get a character from string but the path is like going downstairs in Google Sheets
The string is like:
y C I 6 8 V 5
~5 Z n I L w f
V ~s i w J d _
o R ~4 2 i v f
9 ^ j ~h r u #
Z y Q 7 ~1 u a
T t z u _ ~! Q
G Y n r * t ~^
J A l v F j d
a 2 l - y O B
h B w % n a 4
M t _ P D W a
And expect the output is:
5 s 4 h 1 ! ^
I put ~ in front of the character that demo the path I want to get.
The logic is I will find the first column which cell is 5 and then get start from that cell.
Example sheet link
https://docs.google.com/spreadsheets/d/1UQEGEl_rqAMFePDAGoueTI47xF8T_DyrvJ3de5pkLRA/edit#gid=306981885
I tried auto-fill but it could only incrementally either row or column. And I hope to incremental both row and column.
={INDIRECT("A"&MATCH(5, A1:A14, 0)),
INDIRECT("B"&MATCH(5, A1:A14, 0)+1),
INDIRECT("C"&MATCH(5, A1:A14, 0)+2),
INDIRECT("D"&MATCH(5, A1:A14, 0)+3),
INDIRECT("E"&MATCH(5, A1:A14, 0)+4),
INDIRECT("F"&MATCH(5, A1:A14, 0)+5),
INDIRECT("G"&MATCH(5, A1:A14, 0)+6)}
for a large scale scenario you can use this one and drag it to the right:
=INDIRECT(ADDRESS(MATCH(5, $A1:$A14, 0)+COLUMN()-1, COLUMN(), 4))
You can also do it with an array formula if you want to:
=ArrayFormula(hlookup(column(A2:G13),{column(A2:G13);A2:G13},match(5,A2:A13,0)+column(A2:G13)))
I have two arrays, which are arrAlpha[] and arrPT[]. Array arrAlpha contains the Alphabets and array arrPT[] contains some of the plain letters.following is the code that i wrote in bash shell script to compare elements of both arrays and to store the position elements of arrPT[] in arrAlpha[] to array arrT[]. But when i run i feel like something is wrong in if statement to print out the elements in arrT[]. can anyone help me please?
#!/bin/bash
arrAlpha=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
arrPT=(E K N R S W )
lenPT=${#arrPT}
declare -A arrT
q=0
for((i=0; i<lenPT; i++)) do
for((j=i; j<26; j++)) do
if [ ${arrPT[$i]} = ${arrAlpha[$j]} ]; then
arrT[$q]=$j % 26;
((++q));
fi
done
done
echo ${arrAlpha[#]}
echo ${arrPT[#]}
echo ${arrT[#]}
the expected output is to change elements arrPT to number 0 to 25.
arrAlpha=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
arrPT =(E K N R S W)
arrT =(4 10 13 17 18 22)
Here's a fixed version of your script - there are some style changes that I prefer
arrAlpha=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
arrPT=(E K N R S W )
# array length needs index *
lenPT=${#arrPT[*]}
# seems arrT can be simple indexed array
declare -a arrT
q=0
for((i=0; i<lenPT; ++i)); do
for((j=0; j<26; ++j)); do
if [[ ${arrPT[i]} == ${arrAlpha[j]} ]]; then
# arithmetic inside $(())
arrT[q++]=$((j % 26))
fi
done
done
echo ${arrAlpha[#]}
echo ${arrPT[#]}
echo ${arrT[#]}
The main bug is with this line:
lenPT=${#arrPT}
which should be written like:
lenPT=${#arrPT[#]}
But, in fact, there is no need (even if it is not wrong to use it) for such variable, change this line:
for((i=0; i<lenPT; i++)) do
to:
for((i=0; i<${#arrPT[#]}; i++)) do
Some other issues:
There is no need to mod 26 the value of $j, it will never reach 26.
The array arrT seems to be an indexed array: -a no need for -A.
There is no need for variable q if each result will be in the same position as the index i
Please quote your expansions.
Use printf (more reliable) instead of echo.
The script with all the above done is:
#!/bin/bash
arrAlpha=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
arrPT=(E K N R S W )
declare -a arrT
for((i=0; i<${#arrPT[#]}; i++)) do
for((j=i; j<${#arrAlpha[#]}; j++)) do
[[ ${arrPT[i]} == "${arrAlpha[j]}" ]] && let arrT[i]=j
done
done
printf '%s ' "${arrAlpha[#]}" ; echo
printf '%3s ' "${arrPT[#]}" ; echo
printf '%3s ' "${arrT[#]}" ; echo
Of course, the second loop could be removed by cutting that string at the character:
#!/bin/bash
Alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZ
arrPT=(E K N R S W )
declare -a arrT
for((i=0; i<${#arrPT[#]}; i++)) do
arrT[i]=${Alpha%"${arrPT[i]}"*} # cut the string at the character.
arrT[i]=${#arrT[i]} # Use the len of the cut string.
done
printf '%s ' "$Alpha" ; echo
printf '%3s ' "${arrPT[#]}" ; echo
printf '%3s ' "${arrT[#]}" ; echo
I am trying to generate a password with certain requirements.
When I enter the while loop to generate a random character from the array it is fine until I add a count for my index "$i"
With the following code:
#!/bin/bash
#SET ARRAY VALUES
all=( 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
echo
#SET COUNT VALUES TO 0
numc=0
lowc=0
upc=0
i=0
while true;
do
#GENERATE PASSWORD
phrase[$i]=${all[$RANDOM%62]}
#CHECK IF PASSWORD MEETS REQUIREMENTS
for ((n=0; n<10; n++))
do
if [ ${phrase[$i]} == ${all[$n]} ]
then
echo num ${all[$n]}
let "numc++"
let "i++"
fi
done
I get the error "line 39: [: ==: unary operator expected"
but if I remove the let "i++" line then there is no error. But I need to increase my index in order to exit the loop and check the minimum length of the password
If ${phrase[$i]} (by the way you don't need $ in [$i] context ${phrase[i]} works too) is ever the empty string that if test will become [ == value-of-all-n ] which isn't a valid test.
Either quote the variables (which is almost always the right thing to do) or prevent that from ever being the empty string. (Was that i++ supposed to happen outside the inner loop?)
When I run the script I enter a single argument. I want to store the argument into a variable and access it as a string. So if I enter $ ./script foo I should be able to access f, o, and o. So echo $pass[0] should display f
but what I am finding is that $pass is storing the argument as one piece
so echo $pass[0] displays foo
How do I access the different positions in the string?
#!/bin/bash
all=( 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
pass=$1
max=${#pass}
for (( i=0; i<max; i++ ))
do
for (( n=0; n<10; n++ ))
do
if [ "${pass[$i]}" == ${all[$n]} ]
then
echo true
else
echo false i:$i n:$n pass:${pass[$i]} all:${all[$n]}
fi
done
done
To spell out Etan's comment in the context of this question:
set -- "my password"
chars=()
for ((i=0; i<${#1}; i++)); do chars+=("${1:i:1}"); done
declare -p chars
outputs
declare -a chars='([0]="m" [1]="y" [2]=" " [3]="p" [4]="a" [5]="s" [6]="s" [7]="w" [8]="o" [9]="r" [10]="d")'