I need the cipher key to be able to be infinitely bigger than just the size of the alphabet (26) but still have a final key between 1-26
I am thinking about something like this:
if cipherKey > 26 and :
cipherKey = cipherKey - 26
But I think using a for loop to add the infinitely bigger condition so that if the cipher ends up being infinite + 26 the key will just be 26.
For example if the key is 30, then the cipher key is just 4.
Here is a simple solution
cipherKey = cipherKey%26
Related
I've recently found some lua code and what I found inside was some obfuscated string. That made me wonder what sort of obfuscation technique was used there. Does anybody have an idea?
240.06230.0575240.06240.06270.0675250.0625265.06625270.0675250.0625285.07125260.065260.065260.065250.0625265...
https://pastebin.com/raw/7RkxjWQw
If this string is splitted into xxx.yyyy... chunks (exactly three digits before decimal point), then multiply each number by 800/4001 (the results will be integer!), then convert these integer numbers to ASCII, the hidden sequence of 16 floating point numbers would be revealed:
0.0062562944425795
0.036286507766961
0.02127140110477
0.047547837763604
0.041291543321025
0.0025025177770318
0.011261329996643
0.018768883327738
0.017517624439223
0.042542802209541
0.037537766655477
0.016266365550707
0.0087588122196113
0.057557908871731
0.025025177770318
0.026276436658834
Is the puzzle stops here?
Or should we try to decipher it further?
Ok, we could multiply them all by 32767/41 (the results will be integer!)
5
29
17
38
33
2
9
15
14
34
30
13
7
46
20
21
Hmm, the puzzle seems to be really interesting...
Is it the end?
Just googled it.
That's the passwords encrypted, something Roblox-related
So, OP surely doesn't have decoder script :-)
Ok, finally did it.
function decode_password(encoded_password)
local result = ""
local buffer = ""
for x in encoded_password:gsub("%d%d%d%.", "\0%0"):gmatch"%Z+" do
x = math.floor(tonumber(x) / 5.00125 + 0.5)
if x ~= 95 then
buffer = buffer..string.char(x)
elseif buffer ~= "" then
x = math.floor(tonumber(buffer) * 799.195122 + 0.5)
result = result..("qazwsxedcrfjmik,o0 23456-=\\vtgbyhnul.p;;;/[']1789"):sub(x, x)
buffer = ""
end
end
return result
end
Example 1:
local p = '240.06230.0575240.06240.06270.0675250.0625265.06625270.0675250.0625285.07125260.065260.065260.065250.0625265.06625275.06875285.07125265.06625475.11875240.06230.0575240.06255.06375270.0675250.0625280.07270.0675265.06625240.06275.06875275.06875270.0675270.0675285.07125270.0675245.06125475.11875240.06230.0575240.06250.0625245.06125250.0625275.06875245.06125260.065240.06245.06125245.06125240.06260.065275.06875275.06875475.11875240.06230.0575240.06260.065275.06875265.06625260.065275.06875280.07255.06375275.06875275.06875270.0675255.06375270.0675240.06260.065475.11875240.06230.0575240.06260.065245.06125250.0625285.07125245.06125265.06625260.065255.06375255.06375250.0625245.06125240.06250.0625265.06625475.11875240.06230.0575240.06240.06250.0625265.06625240.06250.0625265.06625245.06125275.06875275.06875275.06875275.06875240.06255.06375245.06125280.07475.11875240.06230.0575240.06245.06125245.06125250.0625270.0675245.06125255.06375250.0625285.07125285.07125285.07125270.0675270.0675260.065255.06375475.11875240.06230.0575240.06245.06125280.07275.06875270.0675280.07280.07280.07255.06375255.06375250.0625275.06875275.06875255.06375280.07475.11875240.06230.0575240.06245.06125275.06875265.06625245.06125275.06875270.0675250.0625260.065260.065255.06375285.07125250.0625250.0625255.06375475.11875240.06230.0575240.06260.065250.0625265.06625260.065250.0625280.07240.06250.0625250.0625240.06285.07125265.06625260.065245.06125475.11875240.06230.0575240.06255.06375275.06875265.06625255.06375275.06875275.06875270.0675270.0675270.0675265.06625265.06625260.065275.06875275.06875475.11875240.06230.0575240.06245.06125270.0675250.0625270.0675270.0675255.06375270.0675265.06625265.06625265.06625240.06275.06875240.06275.06875475.11875240.06230.0575240.06240.06280.07275.06875265.06625280.07280.07245.06125250.0625250.0625245.06125285.07125270.0675245.06125245.06125255.06375475.11875240.06230.0575240.06265.06625275.06875265.06625265.06625275.06875285.07125240.06280.07280.07275.06875245.06125275.06875255.06375245.06125475.11875240.06230.0575240.06250.0625265.06625240.06250.0625265.06625245.06125275.06875275.06875275.06875275.06875240.06255.06375245.06125280.07475.11875240.06230.0575240.06250.0625270.0675250.0625275.06875270.0675260.065255.06375270.0675270.0675265.06625280.07280.07255.06375260.065475.11875'
print(decode_password(p)) --> stophackingme123
Example 2:
for _, info in ipairs(loginDatabase) do
print(info.username, decode_password(info.password))
end
I'm failry new to cryptography and programming as a whole ( mabey a few months) and i started the cryptopal challenges. I got the first 2 done correctly with alot of reading into how to convert things in python.
I'm getting stuck on the code for the 3rd one, "Single-Byte XOR" where they give you a hex string and tell you to write a program to find the key they used to XOR the string.
I am aware of how i would go about doing this (without looking solutions):
1) convert the string to binary
2) loop through all character values XORing them individually with the given ciphertext
3) checking these XORd results to see which one looks "the most english"
I guess im just confused on the way bytes behave in python.
here is my code:
my_ciphertext = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
binary_rep_of_ciphertext = binascii.unhexlify(my_ciphertext)
array_of_ciphertext = bytearray(binary_rep_of_ciphertext)
def xor_string_and_char(my_char_value):
result = array_of_ciphertext ^ my_char_value
return '{:x}'.format(result) # convert back to hexadecimal
x = 0
assert x==0
while x in range(255):
my_plaintext = xor_string_and_char(x)
print('b' + my_plaintext)
x=x+1
I have a question about block cipher using CTR mode. I think i need to find something (value) that when I do 46 XOR value = 43, I get value to be (1011 1101), then i use 0x64(0110 0100) XOR value(1011 1101) but it does not give me 0x72(0111 0010). Did I miss something here? My upstanding is that in order to do this, all i need to do is to find a value that adds counter (in this case is zero) and xor the plain text to get cipher text. Did I miss something here? Thank you in advance.
You know that the 2nd and 3rd block were created by the same key stream (created by concatenating the counter values encrypted by the block cipher).
So for the first byte of the second block you'd have 46 = 43 ^ KK and 51 = P2 ^ KK where KK is the first byte of the key stream. Now KK can be easily calculated, as KK = 46 ^ 43 (KK = 05 if I'm not mistaken). Now P2 = KK ^ 51 or P2 = 05 ^ 51 = 54.
You can simply repeat that for each index into the streams and presto. You don't have to do anything with the counter itself; knowing that the same key and counter were used is enough to generate the same key stream.
Im working on an algorithm to break a modified Vigenere Cipher. The regular Vigenere cipher works in the following way:
Plaintext: ATTACKATDAWN
Key: LEMONLEMONLE
Ciphertext: LXFOPVEFRNHR
Regular Version
CR[i] = (P[i] - 33 + K[i]) mod 94 + 33
Modified Version
CM[i] = (P[i] - 33 + K[i] + CM[i-1] - 33) mod 94 + 33
Notice how the modified version uses previous state/character to generate the new one. My theory to break it is to reverse the modified version back to the regular Vigenere cipher. This way I can apply some frequency analysis and other methods. I need to somehow rearrange that equation such that I have "previousC" on the LHS with C. Since both C and previousC are known values it should be easy to do the reversal (starting with the first character).
My only problem is, how do I rewrite the equation in terms of C and previousC? If someone could point that out that would help a lot.
CR represents the regular Viginere ciphertext, CM the modified Viginere ciphertext
CR[i] = (P[i] + K[i]) mod 26
CM[i] = (P[i] + K[i] + CM[i-1]) mod 26
= (CR[i] + CM[i-1]) mod 26
Now simply solve for the original ciphertext CR
CR[i] = (CM[i] - CM[i-1]) mod 26
Once you have the regular ciphertext, break it as usual.
I am trying to create a function that will use brute force for an academic python project. The password can be limited I want to pass in the password and the function iterate through a set of characters(a-z,A-Z,0-9) trying combinations till the password is found. I know this will be inefficient so for testing lets assume the password is 4 characters long. Any help getting started on writing this function would be appreciated.
gen = itertools.combinations_with_replacement(characters,password_length) #1
for password in gen: #2
check_password(password) #3
here's how it works:
line 1: this creates a generator. it's like a function that remembers where it left off. Check this out for more info: http://getpython3.com/diveintopython3/generators.html. This particular generator goes through all possible combinations of the given characters of the given length.
line 2: for each iteration of the for loop next(gen) is called. This yields the next value
line 3: Do what you need to do
for example if characters = '01234567890' and password_length = 2 then the loop will run through the combinations: ('0','0'), ('0','1'), ('0','2')...('0','9'),('1','0'),('1','1')...('9','9').
For a pre-known length :
import random
a_z = "abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while password != curtry:
currenttry = random.choice(a_z)+random.choice(a_z)+random.choice(a_z)+random.choice(a_z)
For a random length :
import random
a_z = "abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while password != curtry:
leng = random.randint(4,12) #random int between 4 and 12
i = 0
curtry = "lol"
for i<leng:
curtry += random.choice(a_z)