I have a path for a file specified as a string in my code, and I don't want to be visible after luac conversion. Is it possible obfuscate somehow the line?
My code is:
DIR1 = '../../../files/file1.txt'
Thank you!
Yes.
Example:
local Key53 = 8186484168865098
local Key14 = 4887
function decode(str)
local K, F = Key53, 16384 + Key14
return (str:gsub('%x%x',
function(c)
local L = K % 274877906944 -- 2^38
local H = (K - L) / 274877906944
local M = H % 128
c = tonumber(c, 16)
local m = (c + (H - M) / 128) * (2*M + 1) % 256
K = L * F + H + c + m
return string.char(m)
end
))
end
local path = decode"beb81858c47a5fc7e11721921fb7f58ceeb530c4e74034df"
print(path) --> ../../../files/file1.txt
How to encode your own text
Related
So I'm supposed to write a Python program that creates 3 circles of spheres: one on the xy plane, one in the yz plane, and one in the xz plane. Each ring should be centered on the origin, and I'm trying to use three while loops to do this, but nothing is working in VPython and I don't know why.
Web VPython 3.2
from visual import *
x = math.radians(360)
n = m = l = 0
while n <= x:
sphere(pos = vector(math.sin(n), math.cos(m), 1), radius = 0.1, color = color.red)
n = n + (math.radians(30))
m = m + (math.radians(30))
n = m = l = 0
while n <= x:
sphere(post = vector(math.sin(n), m, math.cos(1)), radius = 0.1, color = color.blue)
n = n + (math.radians(30))
l = l + (math.radians(30))
n = m = l = 0
while m <= x:
sphere(pos = vector(n, math.sin(m), math.cos(1)), radius = 0.1, color = color.green)
m = m + (math.radians(30))
l = l + (math.radians(30))
Are you using Web VPython (webvpython.org or equivalently glowscript.org) or the vpython module available for use with installed Python (see installation info at vpython.org)? In either case, simply delete all occurrences of "math."; the math library is available without this (and its use with Web VPython gives an error). Also note that the name of the Python module is "vpython", not "visual".
Trying to convert lua encryption to Node.JS, just need this in it.
("%02x"):format(c)
Once, I got that I'll have it in node.js, so
I tried buffer and it didn't work.
Tried a few other things, and they also didn't work.
Orginal post for this encryption: Low impact encryption formula for ROBLOX Lua
Lua Code:
local Key53 = 8186484168865098
local Key14 = 4887
local inv256
function encode(str)
if not inv256 then
inv256 = {}
for M = 0, 127 do
local inv = -1
repeat
inv = inv + 2
until inv * (2*M + 1) % 256 == 1
inv256[M] = inv
end
end
local K, F = Key53, 16384 + Key14
return (str:gsub('.',
function(m)
local L = K % 274877906944 -- 2^38
local H = (K - L) / 274877906944
local M = H % 128
m = m:byte()
local c = (m * inv256[M] - (H - M) / 128) % 256
K = L * F + H + c + m
--print("lol ".. c)
--print(('%02x'):format(c))
return ('%02x'):format(c)
end
))
end
function decode(str)
local K, F = Key53, 16384 + Key14
return (str:gsub('%x%x',
function(c)
local L = K % 274877906944 -- 2^38
local H = (K - L) / 274877906944
local M = H % 128
c = tonumber(c, 16)
local m = (c + (H - M) / 128) * (2*M + 1) % 256
K = L * F + H + c + m
return string.char(m)
end
))
end
The %02x just convert a decimal to hex. In JS it could be done that way:
function toHex(value) {
let hex = value.toString(16);
if ((hex.length % 2) > 0) {
hex = "0" + hex;
}
return hex;
}
Outputs:
toHex(120) // 78
('%02x'):format(120) -- 78
I am new to CPLEX and I was trying to find an example where the decision variable is in the denominator of the objective function but couldn't. My optimisation problem;
I have tried the following on Python3;
from docplex.mp.model import Model
import numpy as np
N = 1000
S = 10
k = 2
u_i = np.random.rand(N)[:,np.newaxis]
u_ij = np.random.rand(N*S).reshape(N, S)
beta = np.random.rand(N)[:,np.newaxis]
m = Model(name = 'model')
R = range(1, S+1)
idx = [(j) for j in R]
I = m.binary_var_dict(idx)
m.add_constraint(m.sum(I[j] for j in R)<= k)
total_rev = m.sum(beta[i,0] / ( 1 + u_i[i,0]/sum(I[j] * u_ij[j,i-1] for j in R) ) for i in range(N) )
m.maximize(total_rev)
sol = m.solve()
sol.display()
However Im getting the following error when running the line;
total_rev = m.sum(beta[i,0] / ( 1 + u_i[i,0]/sum(I[j] * u_ij[j,i-1] for j in R) ) for i in range(N) )
Error :
DOcplexException: Expression 0.564x1+0.057x2+0.342x3+0.835x4+0.452x5+0.802x6+0.324x7+0.763x8+0.264x9+0.226x10 cannot be used as divider of 0.17966220449798675
Can you please help me to overcome this error?
Since your objective is not linear you should use CPO within CPLEX
from docplex.cp.model import CpoModel
import numpy as np
N = 10
S = 10
k = 2
u_i = np.random.rand(N)[:,np.newaxis]
u_ij = np.random.rand(N*S).reshape(N, S)
beta = np.random.rand(N)[:,np.newaxis]
m = CpoModel(name = 'model')
R = range(1, S)
idx = [(j) for j in R]
I = m.binary_var_dict(idx)
m.add_constraint(m.sum(I[j] for j in R)<= k)
total_rev = m.sum(beta[i,0] / ( 1 + u_i[i,0]/sum(I[j] * u_ij[j,i-1] for j in R) ) for i in range(N) )
m.maximize(total_rev)
sol=m.solve()
for i in R:
print(sol[I[i]])
works fine
Here's the code
def check_right_angle(a, b, c):
if a**2 + b**2 == c**2:
return True
return False
def mn_to_abc(m, n):
return m**2 - n**2, 2 * m * n, m**2 + n**2
list_solutions = []
for i in range(1001): #Getting all primitive triples using Euclid's formula <= 1000
list_solutions.append([])
if i == 0:
continue
for m in range(1, int(i/2) - 1):
n = int(i / (2 * m) - m)
if m > n and n > 0:
a, b, c = mn_to_abc(m, n)
if check_right_angle(a, b, c) and a + b + c == i:
list_solutions[i].append((a, b, c))
for item in list_solutions: #Getting the remaining triples by using the primitive triples
for abc in item:
for i in range(1, 85): # 85 since 3x + 4x + 5x = 1000 => x = 83.3333 = 84
try:
new_a = abc[0] * i
new_b = abc[1] * i
new_c = abc[2] * i
if new_a + new_b + new_c <= 1000:
list_solutions[new_a + new_b + new_c].append((new_a, new_b, new_c))
else:
break
except:
continue
print(len(list_solutions[120]))
print(list_solutions[120])
The situation is mostly explained in the title but this code refuses to run unless line 30 is replaced with either one of the following lines:
list_solutions[new_a + new_b + new_c].append((new_a+ new_b, new_c))
list_solutions[new_a + new_b + new_c].append((new_a+ new_b+ new_c))
list_solutions[new_a + new_b + new_c].append((new_a, new_b+ new_c))
I've even tried to append it as a list instead of a tuple but to no avail. Such a weird thing to run into.
Never mind fellas, just had an epiphany. Turns out adding to a list you're iterating is a terrible, terrible idea. Before line 30 I added this code:
if not (new_a, new_b, new_c) in list_solutions[new_a + new_b + new_c]:
You might have noticed that I'm still adding to that same list I'm iterating through, but for some reason, as long as the items in that list don't repeat themselves, everything is fine.
I would close this question now, but it's telling me I can only accept my own answer in 2 days.
Could you please help me speed up this code?
It takes a very long time to run because of how big the input file is, thank you to anyone who helps out.
racers = [int(file[0].split()[0]) / float(x) for x in file[0].split()[1::]]
print("hi")
def av(race):
race = race.split()
j = 0
while j != len([float(race[0]) / float(x) for x in race[1::]]):
racers[j] = [float(race[0]) / float(x) for x in race[1::]][j] + racers[j]
j += 1
for i in range(1, len(file)):
av(file[i])
a = min(racers)
del(racers[racers.index(min(racers))])
b = min(racers)
c = b-a
h = int(c)
c-=h
m = int(c * 60)
c-=m/60
s = round(c * 60 * 60)
print(str(h) + "h" + str(m) + "m" + str(s) + "s")