I have a ridiculous code segment in one of my programs right now:
str(len(str(len(var_text)**255)))
Is there an easy way to shorten that? ‘Cause, frankly, that’s ridiculous.
A option to convert a number >500 digits to scientific notation would also be helpful
(that’s what I’m trying to do)
Full code:
print("Useless code rating:" , str(len(var_text)**255)[1] + "e" + str(len(str(len(var_text)**255))))
TL;DR:
y = 2.408 * len(var_text)Lets assume that your passkey is a string of characters with 256 characters available (0-255). Then just as a 16bit number holds 65536 numbers (2**16) the permutations of a string of equal length would be
If you want the number of (decimal) digits in n_perms, consider the logarithm:
So we have
length = floor(log10(n_perms)) + 1. In python,introunds down anyway, so I’d say you wantI’d argue that ‘shortening’ ugly code isn’t always the best way – you want it to be clear what you’re doing.
Edit: On further consideration I realised that choosing base-10 to find the length of your permutations is really arbitrary anyway – so why not choose base-256!
You are effectively just finding the length of your passkey in a different base…
Edit 2: Stand back, I’m going to attempt Mathematics!
So, how’s this for short: