local function count_ones(num)
local count = 0
while num ~= 0 do
if(bit.band(num, 1) == 1) then
count = count + 1
end
num = bit.rshift(num, 1)
end
return count
end
local function find_password_case(smbstate, domain, username, password)
-- Figure out how many possibilities exist
local max = math.pow(2, #password) - 1
-- Create an array of them, starting with all the values whose binary representation has no ones, then one one, then two ones, etc.
local ordered = {}
-- Loop backwards from the length of the password to 0. At each spot, put all numbers that have that many '1' bits
for i = 0, #password, 1 do
for j = max, 0, -1 do
if(count_ones(j) == i) then
table.insert(ordered, j)
end
end
end
io.write(nsedebug.tostr(ordered))
end
1: 0
2: 8
3: 4
4: 2
5: 1
6: 12
7: 10
8: 9
9: 6
10: 5
11: 3
12: 14
13: 13
14: 11
15: 7
16: 15
local function convert_case(str, num)
local pos = #str
-- Don't bother with blank strings (we probably won't get here anyway, but it doesn't hurt)
if(str == "") then
return ""
end
while(num ~= 0) do
-- Check if the bit we're at is '1'
if(bit.band(num, 1) == 1) then
-- Check if we're at the beginning or end (or both) of the string -- those are special cases
if(pos == #str and pos == 1) then
str = string.upper(string.sub(str, pos, pos))
elseif(pos == #str) then
str = string.sub(str, 1, pos - 1) .. string.upper(string.sub(str, pos, pos))
elseif(pos == 1) then
str = string.upper(string.sub(str, pos, pos)) .. string.sub(str, pos + 1, #str)
else
str = string.sub(str, 1, pos - 1) .. string.upper(string.sub(str, pos, pos)) .. string.sub(str, pos + 1, #str)
end
end
num = bit.rshift(num, 1)
pos = pos - 1
end
return str
end
1: test
2: Test
3: tEst
4: teSt
5: tesT
6: TEst
7: TeSt
8: TesT
9: tESt
10: tEsT
11: teST
12: TESt
13: TEsT
14: TeST
15: tEST
16: TEST
List<String> findPassword(String original) {
List<String> passwords = new ArrayList<String>();
for (int i = 0; i <= original.length(); i++) {
// Create i capitals in original
passwords.addAll(insertCapitals(original, i));
}
return passwords;
}
List<String> insertCapitals(String original, int howmany) {
List<String> passwords = new ArrayList<String>();
if(howmany == 0) {
// Don't need to add any more capitals; only possibility is the original
passwords.add(original);
} else if(original.length() == 0) {
// We need to add more capitals, but there's nowhere to put them; no possibilities
} else {
// Generate all the cases for the first char uppercase
for (String x : insertCapitals(original.substring(1), howmany - 1))
passwords.add(original.substring(0, 1).toUpperCase() + x);
// Generate all the cases for first char lowercase
for (String x : insertCapitals(original.substring(1), howmany))
passwords.add(original.charAt(0) + x);
}
return passwords;
}
#include <stdio.h>
#include <string.h>
#define N 5
void print_case_mask(const char *case_mask);
int main(int argc, char **argv) {
unsigned long stack[N], t;
char case_mask[1 + (N >> 3)];
stack[0] = 0;
t = 0;
memset(case_mask,0x00,sizeof(case_mask));
while (stack[0] < N) {
case_mask[stack[t] >> 3] ^= 1 << (stack[t] & 0x7);
print_case_mask(case_mask);
if (stack[t] >= N-1) {
case_mask[stack[t] >> 3] ^= 1 << (stack[t] & 0x7);
t -= (t > 0);
}
else if (t < N-1) {
case_mask[stack[t] >> 3] ^= 1 << (stack[t] & 0x7);
stack[t+1] = stack[t];
t++;
}
case_mask[stack[t] >> 3] ^= 1 << (stack[t] & 0x7);
stack[t]++;
}
return 0;
}
void print_case_mask(const char *case_mask) {
unsigned long i;
for (i = 0; i < N; ++i) {
putchar(case_mask[i >> 3] & (1 << (i & 0x7)) ? 'U' : 'L');
}
putchar('\n');
}
ULLLL
UULLL
UUULL
UUUUL
UUUUU
UUULU
UULUL
UULUU
UULLU
ULULL
ULUUL
ULUUU
ULULU
ULLUL
ULLUU
ULLLU
LULLL
LUULL
LUUUL
LUUUU
LUULU
LULUL
LULUU
LULLU
LLULL
LLUUL
LLUUU
LLULU
LLLUL
LLLUU
LLLLU
char ncase_mask[1 + (N >> 3)];
memset(ncase_mask, 0xff, sizeof(ncase_mask));
/* Annotate the algorithm with bit toggling in the same places as with the first algorithm */
[latex]
% TODO: Fix LaTeX in forum
\begin{align*}
& G =(V,E) \\
& i < j \Leftrightarrow (i,j) \in E \quad \forall i,j \in V \\
\end{align*}
[/latex]
[latex]
% TODO: Fix LaTeX in forum
\begin{align*}
& G =(V,E) \\
& i < j \Leftrightarrow (i,j) \in E \quad \forall i,j \in V \\
\end{align*}
[/latex]
[latex] \textbf{It works.}[/latex]
But my knowledge of LaTeX doesn't.
Awesome, but '%' is the comment delimiter in LaTeX, the TODO line should not appear.[latex]
% TODO: Fix LaTeX in forum
\begin{align*}
& G =(V,E) \\
& i < j \Leftrightarrow (i,j) \in E \quad \forall i,j \in V \\
\end{align*}
[/latex]
[latex] \textbf{It works.}[/latex]
But my knowledge of LaTeX doesn't.
It didn't work when he posted it. It has since been fixed.