I mean, depending on the security requirements, that could be passable. Why use complex algorithm when you are just trying to prevent just some rando from looking at something. This is probably legitimately enough to stop 90% of people from just opening and editing something like a save file for a game.
Hell, if I'm not motivated enough to go further than just opening up the save file in a text editor, this would even stop me!
You don't have to make something complex to scare away somebody just looking at the thing from trying to edit it: I would never guess to just bit shift the data, I'd just open it, see a bunch of unicode and then close it immediately.
It’s using arithmetic shift right - so the highest bit will be equal to the second highest bit after decryption, it’s not exactly LOSSY since all the data is there, but the result isn’t the same as the original, you need to manually remove the highest (sign) bit to get the original result
Oh, I meant that it’s the encryption that is lossy, not the decryption. By encrypting the way they do, they have lost data. The decryption only makes an assumption that valid encryption was done.
If the encryption was lossless, the decryption can still be scrambled if the second highest bit was set in the input, because then the highest bit will be in the output (different from input) - not exactly lossy because that can be fixed, but it’s not as simple as “not lossy” like you said
I mean... we are arguing semantics at this point because it’s the whole process that matters. I see what you are getting at, and I agree it’s not a good process. I wouldn’t call it lossy because it does not lose information, it adds it in fact. It makes a different invalid assumption about the input.
If both the last bit and second to last bit are the same, no problem.
The problem is really that the entire process makes an assumption about the input that is not checked or asserted.
I wouldn’t call it lossy because it does not lose information, it adds it in fact.
No? the last bit is not new information as it’s always redundant with the second to last bit, it scrambles the information for any meaningful usage other than bitwise stringification (the literal bits it contains, not a binary number string)
No, in 2's complement it could cause problems multiple ways for large numbers.
0x40000000 shifted left once would become -1, and then shifted right once would remain -1. EDIT: I was wrong, sorry! I was correct that after the left shift it would be 0x80000000, but that is not -1. It's -2147483648. Shifted right it would become 0xC0000000, which is -1,073,741,823.
This could be corrected by using the logical shift right operator ">>>".
Yes. But I'm also continuing a discussion to clarify for u/zeGolem83 that they are misunderstanding the way that negative numbers are represented in computers, and giving a pointer that explains why that is, and how to avoid a potential pitfall in Java given that there are no unsigned types.
Part of the value of this sub is the discussions of what to do in place of the bad code. I've learned from this sub, just trying to contribute.
Something people don't realize, there are two types of shifts, arithmetic and logical shifts. A logical shift just moves bits left and right. A 0 is always shifted in. Its called a logical shift because it assumes the data is just is non-numerical data that might need to be moved around, for things like masks. It just happens to work for unsigned numbers too. This is what an logical shift does (using 8 bit unsigned):
An arithmetic shift, as the name implies, is intended for numerical data. Although it doesn't work for unsigned numbers. Its purpose is to maintain the rule that a right shift divides the value by two, and a left shift multiplies it by 2. The most significant bit (the sign bit) always remains as is. When shifting left a zero is shifted in. When shifting right, if the MSB is 1 a 1 is shifted in, if the MSB is 0 a 0 is shifted in. So this is what an arithmetic shift does (using 8 bit signed):
Which shift is used depends on whether you've got signed or unsigned values. Unsigned results in a logical shift, signed result in an arithmetic shift. The fact that only a right shift changes is why there's only a right logical shift.
You'll get errors with small values too, not just large ones. Shifting -8 with an arithmetic shift gives -4, a logical shift gives 124. Its a result of the fact that a large value in one system is a small one in the other. It means you have to be careful when dealing with signed and unsigned types, the result might not be what you expect.
To borrow a quote from another website:
It's important to remember that the unsigned keyword affects theinterpretation**,** nottherepresentation of a number.
Although if you're doing type conversion from chars to longs you'll probably end up with other problems. Unless you're shifting two or four characters at a time. Well, that has problems too.
Yes, but seems doubtful as it takes a long instead of a byte. But, interesting idea: they may cast bytes to long first, and thus none of the 8 bits are actually lost.
Well you shift a 64 bit int to the left so the highest value bit will be lost. There are a few other problems with that code though... because right shifting of signed integer dont work like you would expect it at first. But lets not get into that topic.
You could cast it as unsigned first. In C there's no difference to whether or not the type is unsigned or signed until you're trying to make comparisons, print values, or otherwise send them out of the system. So if you just treat it all as unsigned until you're ready to print it back out "unencrypted", then you're fine. Except for the lost bit but we only need 63-bits right?
Just a note which some people aren't aware of is that long on windows is actually 32 bits strangely. I know we are like two levels of hypothetical deep here but I thought it's slightly relevant.
Yes it does. It does inverse the “encryption”. Assuming of course the most significant bit in the original data is never set, which is a reasonable assumption given it’s example code.
You are right. Though the way it works in Java that isn’t touched. I meant the MSB past the sign bit. So technically the second most significant bit. Or the most significant number bit. Should have been a bit more clear on that. In short for small enough numbers this code works. Which is good enough for demonstration code. Which is the whole point.
In those cases it’s generally a good idea to check that limited range at the top of the function so you can throw an exception or at least log an error if someone uses the method wrong.
ya know what they say, data is the oil of the 21st century. so it's economicly a good idea to position yourself at a point where all this data passes through...
I know that Troy Hunt speaks highly of NordVPN, he's in fact working as an advisor for them and seems to trust their work.
Depending on the country you are in, you are giving your data to way more parties than just your ISP. If you are living in any of the Five Eyes countries (that includes the US) than your data is also with the NSA and the intelligence agencies of the other countries.
Almost all VPN providers claim to prevent that by not logging their users data, but there have been cases where those claims turned out to be false(often for free VPNs). And in those cases it would be possible that this data could be shared with those agencies and other parties. In the case of the US the VPN provider could even be legally forced to hand out that data.
NordVPN has been audited by PwC to explicitly verify that they are not logging the user activity and PwC has in fact concluded (twice) that NordVPN does not log user activities.
And even if they were: NordVPN is registered in Panama which means that they are outside of the US jurisdiction so even if they log data they could not be forced to hand it over to the NSA etc.
I must sound like a NordVPN sales guy... the truth is I am a customer and have done extensive research before I have decided on my VPN provider of choice.
If you're not using an ad blocker, they'll 100% still know it's you.
Even with an ad blocker, they'll still have ways to at least narrow down who you are. The fact you're using a VPN (they'll know this) is a data point on its own.
I forget if the encryption is the approximate equivalent of /2 or x2, but assuming it's the x2, that's actually ok: their goal of encryption is just to deter the most basic of tampering. If you can get past this you probably know what you are doing enough to not complain if you mess it up.
This is a good illustration that context is important. If this was used for anything in banking, dealing with passwords, etc it would be horrible. If this was used to hide player health or other stats in a game from memory scans it’s something that could do that purpose.
I mean obviously this is idiotic but wouldn’t it work with signed (TC) and unsigned ints just extended into a long and then truncated back to int after decryption? For arguments sake lol
ok this reminded me a little about a feature idea i had for languages. like where you could put functions and stuff in the arguments. for example(mind you i'm on mobile and don't know the markdown):
void idk(string num.toString) { //idk do stuff here }
or in this post,
public static long encrypt(long a << 1) { return a; }
maybe this is a bad feature, maybe i'm bad at typing, maybe i shouldn't've said this, but idk i hope y'all have a nice day
11
u/_Sherlock-Holmes_ Mar 13 '21
wtf he achived with it?
3
u/Bastian_5123 Mar 26 '21
I mean, depending on the security requirements, that could be passable. Why use complex algorithm when you are just trying to prevent just some rando from looking at something. This is probably legitimately enough to stop 90% of people from just opening and editing something like a save file for a game.
Hell, if I'm not motivated enough to go further than just opening up the save file in a text editor, this would even stop me!
You don't have to make something complex to scare away somebody just looking at the thing from trying to edit it: I would never guess to just bit shift the data, I'd just open it, see a bunch of unicode and then close it immediately.
653
u/Bobitsmagic Mar 13 '21
What does he do with the lost bit? Do you only choose data where the last bit is irrelevant? xD
100
u/Spire Mar 13 '21
For extra security, encrypt each piece of data 64 times. This is known as SHL64 and is one of the most difficult forms of encryption to break.
236
u/TheBrainStone Mar 13 '21
If that is used as a demonstration for how to handle encryption in your code then I’d say that’s fair. For anything else that’s just insane.
78
u/[deleted] Mar 13 '21 edited Mar 13 '21
Image Transcription: Code
[Dark Theme.]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
104
u/alexugoku Mar 13 '21
57
u/TheForwardMomentum Mar 13 '21
north vpn be like
12
u/[deleted] Mar 13 '21
Bad function names, should be
obfuscateanddeobfuscate.9
u/vasilescur Mar 13 '21
8
u/ekolis Mar 13 '21
When all you know of encryption is the be Caesar cipher and you need to encrypt a number...
13
u/cyberneticSyntax Mar 13 '21
I love that it only says "Title" where a title description should be, gives it a more "cryptic" vibe.
6
u/[deleted] Mar 13 '21
This is unironically how rpg maker encrypts its memory lmfao
5
u/schteppe Mar 13 '21
It’ll work for ascii characters though... since the uppermost bit is not used
5
u/EvilPettingZoo42 Mar 13 '21
This is a good illustration that context is important. If this was used for anything in banking, dealing with passwords, etc it would be horrible. If this was used to hide player health or other stats in a game from memory scans it’s something that could do that purpose.
2
u/PockelHockel Mar 13 '21
Wow, that's... secure
2
u/amanj41 Mar 13 '21
I mean obviously this is idiotic but wouldn’t it work with signed (TC) and unsigned ints just extended into a long and then truncated back to int after decryption? For arguments sake lol
2
u/an-obviousthrowaway Mar 13 '21
Saw something just like this in among us code for “decrypting” purchase history. (Early versions didn’t use il2cpp)
2
u/causticacrostic Mar 14 '21
heh, and they say never roll your own crypto. doesn't seem so hard to me. i must be a rare genius
1
u/Sawertynn Jun 19 '21
Oh c'mon man, I knew that was a joke. I wanted to add something to it.
1
u/[deleted] Aug 23 '21
ok this reminded me a little about a feature idea i had for languages. like where you could put functions and stuff in the arguments. for example(mind you i'm on mobile and don't know the markdown):
void idk(string num.toString) {
//idk do stuff here }
or in this post,
public static long encrypt(long a << 1) {
return a;
}
maybe this is a bad feature, maybe i'm bad at typing, maybe i shouldn't've said this, but idk i hope y'all have a nice day