Jump to content




encrypting

lua networking

  • You cannot reply to this topic
26 replies to this topic

#1 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 21 June 2012 - 11:02 PM

I am encrypting messages and was wondering how i break up words and such to encrypt them. I am new to encryption and am not exactly all knowledgeable. And suggestions?

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 21 June 2012 - 11:06 PM

What kind of encryption do you use?
And why do you want to split the words? you should encrypt the whole string.

#3 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 21 June 2012 - 11:19 PM

How? I don't have anything coded yet... I have looked at the keymapper api but i don't think that is it...

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 21 June 2012 - 11:27 PM

View Posttfoote, on 21 June 2012 - 11:19 PM, said:

How? I don't have anything coded yet... I have looked at the keymapper api but i don't think that is it...
:P/>
Well, first things first, what do you need to encrypt? passwords? network messages? files?
For passwords you should use some hashing algorithm, like md5 or sha.
For network messages, use asymetric key encryption.
And for files and other things, you probably want to use symetric key encryption.
There's a lot of hashing/encryption algorithms, you need to use the one that fits your needs (or create your own).

#5 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 21 June 2012 - 11:29 PM

Im setting up a Server inside a server... It composes of firewalls, e-mail, FTP, Chat. I need to know how to encrypt

#6 kazagistar

  • Members
  • 365 posts

Posted 21 June 2012 - 11:46 PM

Right, how about this... you make the email, ftp, firewall, and chat all work first, and create a dummy encryption function for now (like "function encrypt(str) return str end") and then get to it once you have something to secure.

Encryption is very very very hard to do right. If you want to come up with some random not-very-secure encryption of your own, use string.bytes and string.char to get it in and out of a more easy to use format.

#7 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 21 June 2012 - 11:49 PM

I like your thinking... I'll do that... But i still want you to post how to encrypt so that when im ready i will have an e-mail from this forum on how to do it.

#8 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 22 June 2012 - 12:15 AM

Again, it depends on what you need to encrypt.
I suppose that asymetric key encryption would be the best for network things, but I don't think it's necesary, since with modems you can send messages between two computers and noone else can see it.
If you still want to add encryption, do some research on the existing algorithms and how they work.

#9 Bossman201

  • New Members
  • 92 posts

Posted 22 June 2012 - 04:00 AM

Should be relatively secure, of course if anyone figures out how you're encrypting it, there's a very easy way to decode this.
term.clear()
term.setCursorPos(1, 1)
local iEncrypt = nil
local sMessage = nil
local tWords = {}

function NULLencrypt(tWords)  --tried to encrypt as a whole before I realized I could do it during table.insert
for i = 1, #tWords do --function NULLencrypt is not necessary in program code as it is not used
  local sTemp = nil
  for i = 1, string.len(tWords[i]) do
   if i == 1 then
	sTemp = tWords[i]:byte(i)
   else
	sTemp = sTemp .. " " .. tWords[i]:byte(i)
   end
   tWords[i] = sTemp
  end
end
return true
end

function encrypt(string)
local sTemp = nil
for i = 1, string.len(string) do
  if i == 1 then
   sTemp = string:byte(i)
  else
   sTemp = sTemp .. " " .. string:byte(i)
  end
end
return sTemp
end

term.write("Enter message: ")
sMessage = tostring(io.read())

for match in string.gmatch(sMessage, "[^ t]+") do
table.insert( tWords, encrypt(match) .. "b" )
end

for i = 1, #tWords do
print(tWords[i])
end

The way I would encrypt this would be to add another function that breaks down each "line" of output and multiplies each char code by a user-defined number. This number would then be sent at the very beginning of any rednet message so that the receiving computer can decode the message. Any computers spying will only get a string of huge numbers that won't mean anything. I probably will add this and a decoder to bosschat since I've done the legwork already.

To further screw with spy's, reverse each word before encryption, then reverse the entire table. Then laugh as they flip their tables trying to code a way around your encryption.
(╯°□°)╯︵ ┻━┻

Sample output:
Spoiler


#10 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 22 June 2012 - 04:32 AM

View PostBossman201, on 22 June 2012 - 04:00 AM, said:

Should be relatively secure, of course if anyone figures out how you're encrypting it, there's a very easy way to decode this.
term.clear()
term.setCursorPos(1, 1)
local iEncrypt = nil
local sMessage = nil
local tWords = {}

function NULLencrypt(tWords)  --tried to encrypt as a whole before I realized I could do it during table.insert
for i = 1, #tWords do --function NULLencrypt is not necessary in program code as it is not used
  local sTemp = nil
  for i = 1, string.len(tWords[i]) do
   if i == 1 then
	sTemp = tWords[i]:byte(i)
   else
	sTemp = sTemp .. " " .. tWords[i]:byte(i)
   end
   tWords[i] = sTemp
  end
end
return true
end

function encrypt(string)
local sTemp = nil
for i = 1, string.len(string) do
  if i == 1 then
   sTemp = string:byte(i)
  else
   sTemp = sTemp .. " " .. string:byte(i)
  end
end
return sTemp
end

term.write("Enter message: ")
sMessage = tostring(io.read())

for match in string.gmatch(sMessage, "[^ t]+") do
table.insert( tWords, encrypt(match) .. "b" )
end

for i = 1, #tWords do
print(tWords[i])
end

The way I would encrypt this would be to add another function that breaks down each "line" of output and multiplies each char code by a user-defined number. This number would then be sent at the very beginning of any rednet message so that the receiving computer can decode the message. Any computers spying will only get a string of huge numbers that won't mean anything. I probably will add this and a decoder to bosschat since I've done the legwork already.

To further screw with spy's, reverse each word before encryption, then reverse the entire table. Then laugh as they flip their tables trying to code a way around your encryption.
(╯°□°)╯︵ ┻━┻

Sample output:
Spoiler

That is not encryption nowhere near it.
Not even remotely secure.

#11 Bossman201

  • New Members
  • 92 posts

Posted 22 June 2012 - 08:20 AM

No, that is just a basic way to prepare a message for encryption. I've left plenty for OP to code on his own. He asked how to break up words which would be
local tWords = {}
for match in string.gmatch(sMessage, "[^ t]+") do
 table.insert( tWords, match .. "b" )
end
Technically, it is still encryption because...I can't read it, can you?

Quote

In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called a cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
-Taken from wikipedia, this is exactly what my code does. The special knowledge or 'key' would be being able to tell that it's just character codes, which a lot of us can tell. So no, you're right, it's not secure. But it is encryption.

#12 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 22 June 2012 - 08:33 AM

View PostBossman201, on 22 June 2012 - 08:20 AM, said:

No, that is just a basic way to prepare a message for encryption. I've left plenty for OP to code on his own. He asked how to break up words which would be
local tWords = {}
for match in string.gmatch(sMessage, "[^ t]+") do
table.insert( tWords, match .. "b" )
end
Technically, it is still encryption because...I can't read it, can you?

Quote

In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called a cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
-Taken from wikipedia, this is exactly what my code does. The special knowledge or 'key' would be being able to tell that it's just character codes, which a lot of us can tell. So no, you're right, it's not secure. But it is encryption.

Your not using an algorithm are you?
And the special knowledge/key would be if you knew the key you need to decrypt it like in symmetrical / asymmetrical encryption or the decryption algorithm.

//EDIT: This is the encryption api from my string utils api, I'm not saying it is extremely secure but it does require you to know the key for encryption/decryption i.e. symmetrical, EncryptionUtils.lua

#13 kazagistar

  • Members
  • 365 posts

Posted 22 June 2012 - 01:35 PM

Until we can get lockable bootloader, there is no security. You can al and ways just shut down a computer, put a disk with a startup next to it, see how they do their encryption and read their key, and break it.

#14 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 June 2012 - 02:27 PM

View Posttomass1996, on 22 June 2012 - 08:33 AM, said:

View PostBossman201, on 22 June 2012 - 08:20 AM, said:

No, that is just a basic way to prepare a message for encryption. I've left plenty for OP to code on his own. He asked how to break up words which would be
local tWords = {}
for match in string.gmatch(sMessage, "[^ t]+") do
table.insert( tWords, match .. "b" )
end
Technically, it is still encryption because...I can't read it, can you?

Quote

In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called a cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
-Taken from wikipedia, this is exactly what my code does. The special knowledge or 'key' would be being able to tell that it's just character codes, which a lot of us can tell. So no, you're right, it's not secure. But it is encryption.

Your not using an algorithm are you?
And the special knowledge/key would be if you knew the key you need to decrypt it like in symmetrical / asymmetrical encryption or the decryption algorithm.

//EDIT: This is the encryption api from my string utils api, I'm not saying it is extremely secure but it does require you to know the key for encryption/decryption i.e. symmetrical, EncryptionUtils.lua

You don't understand what the word algorithm means. He's using an algorithm. However, that's an obfuscation technique, not an encryption technique. Security through obscurity is no security at all.

#15 kazagistar

  • Members
  • 365 posts

Posted 22 June 2012 - 03:06 PM

View PostLyqyd, on 22 June 2012 - 02:27 PM, said:

You don't understand what the word algorithm means. He's using an algorithm. However, that's an obfuscation technique, not an encryption technique. Security through obscurity is no security at all.


Again, until we get a bootloader lock, security through obscurity is the only possibility for any computer that someone can access and place a disk drive next to. You can, theoretically, use asynchronous cryptographic message signing to send messages between properly secured computers across an unsecured network, I guess.

I was trying to figure out how to create a dynamic trusted network amongst work turtles. Unfortunately, the best I can come up with is one where they store encryption keys in memory only, and their startup script just has them path back to a secured base and get reset. (I am still hoping the bios will get updated before I implement my secured networking system, so I haven't implemented it yet.)

#16 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 22 June 2012 - 03:42 PM

View Postkazagistar, on 22 June 2012 - 03:06 PM, said:

Again, until we get a bootloader lock, security through obscurity is the only possibility for any computer that someone can access and place a disk drive next to.
Why? If only you know the key, there's no way to decrypt the message (given you use a good encryption algorithm).

#17 kazagistar

  • Members
  • 365 posts

Posted 22 June 2012 - 04:06 PM

View PostMysticT, on 22 June 2012 - 03:42 PM, said:

Why? If only you know the key, there's no way to decrypt the message (given you use a good encryption algorithm).

What does "you" mean? Both sender and receiver computers must know some kind of cipher, and if one of them is compromised, then the hacker has access to both your algorithm and your cipher, and your messages are no longer fully trusted.

Of course, if you only store your password in memory, then you are fine, but that means you have to type in the password manually on every single computer you want to be able to communicate, and verify that it is not compromised first.

#18 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 22 June 2012 - 05:29 PM

Well, I wasn't thinking on network encryption, since it would be unnecesary. You can simply send the message to a computer, and no one else can see the message.
If you want to make some network system, with routers and everything, then it could be usefull. Without that is just adding unnecesary overhead.
Also, why would having a bootloader lock be helpfull with this? It would only hide your code, wich is pretty much security through obscurity.

#19 kazagistar

  • Members
  • 365 posts

Posted 22 June 2012 - 06:38 PM

View PostMysticT, on 22 June 2012 - 05:29 PM, said:

Well, I wasn't thinking on network encryption, since it would be unnecesary. You can simply send the message to a computer, and no one else can see the message.
If you want to make some network system, with routers and everything, then it could be usefull. Without that is just adding unnecesary overhead.
Also, why would having a bootloader lock be helpfull with this? It would only hide your code, wich is pretty much security through obscurity.
If you can hold a list of "verified" computer IDs that you can trust absolutely, and only send and receive messages from those nodes, then you don't even need encryption. Unfortunately, a node that was previously verified can be compromised, and no longer trusted. If you can secure a bootloader, then if you code it correctly, your network is safe. If you cannot secure your bootloader, then if any computer can be physically accessed, and you will be unsafe no matter what you do, in terms of networking.

Yes, if you just use a password and encryption for storing and retrieving local files, you can be safe. But what is the point?

#20 OmegaVest

  • Members
  • 436 posts

Posted 22 June 2012 - 07:08 PM

Okay, before a mod comes and shuts this down, how about we agree that the poster's question was answered, or at least addressed to the point that they responded with a "Going to do that".

Everything else has basically been saying NOTHING, ANYWHERE IS SAFE!!! We get it. A man with a crowbar can't easily get through an iron door, but a man with TNT can. Everything that has an access point has a weakness. Shut up, get over it, manage your computers responsibly. Never store something you would not want to lose on them. If you want to keep something safe, use a floppy that you keep in your inventory. Or, if you have EE, put it in a bag. If the bag is destroyed, just make a new one. It will bring back YOUR inventory.

And, the point is always "BECAUSE WE CAN".
Can we please move on?




Sorry for the Capslocks. I needed to vent. And get you to pay attention to that specific text.


TFoote, use Bossman201's code. As has been said, Obfuscation is best until such time as we can just mod bios.lua. Which is unlikely to happen. But be aware that anytime you just rearrange the text, someone, somehow, will figure out how to put it back right.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users