๐ถ NFC
Indirecta Near Field Communication Protocolโ
Our take on NFC Functionality, in Robloxโ
This protocol allows different FOSD devices to transmit and receive data, for example, the iComm and a door access control keypad, an rfid fob, etc.
๐NFC Protocol Encryption & Decryptionโ
๐ _encโ
Encrypts a string using a vector-based XOR encryption algorithm.
Parametersโ
string
: The string to be encrypted.Vector3
: A Vector3 object containing encryption key values.
Returnsโ
string
: ๐ The encrypted string.
โ๏ธ Algorithm Design
The encryption algorithm works as follows:
- The string is iterated character by character.
- The ASCII value of the character is obtained using string.byte.
- The key part (X, Y, or Z) is selected based on the keyIndex, which cycles through the key values.
- The character value is XORed with the key part value using bit32.bxor.
- The encrypted character is converted back to a string using string.char.
- The encrypted character is appended to the encrypted string.
- The keyIndex is incremented and wrapped around to 1 if it exceeds 3.
- Steps 2-7 are repeated for each character in the string.
- The final encrypted string is returned.
Example usageโ
local str = "Hello, world!"
local v3 = Vector3.new(1, 2, 3)
local encryptedStr = NFC:_enc(str, v3)
print(encryptedStr)
NFC._enc = function(self, str: string, v3: Vector3)
local encrypted = ""
local keyIndex = 1
local key = {v3.X, v3.Y, v3.Z}
for i = 1, #str do
local char = string.byte(str, i)
local keyPart = key[keyIndex]
local encryptedChar = bit32.bxor(char, keyPart)
encrypted = encrypted .. string.char(encryptedChar)
keyIndex = keyIndex + 1
if keyIndex > 3 then
keyIndex = 1
end
end
return encrypted
end
๐ _decโ
Decrypts an encrypted string using a vector-based XOR decryption algorithm.
Parameters:โ
string
: The encrypted string to be decrypted.Vector3
: A Vector3 object containing decryption key values.
Returns:โ
string
: ๐ The decrypted string.
โ๏ธ Algorithm Design
The decryption algorithm works in a similar way to the encryption algorithm:
- The encrypted string is iterated character by character.
- The ASCII value of the character is obtained using string.byte.
- The key part (X, Y, or Z) is selected based on the keyIndex, which cycles through the key values.
- The character value is XORed with the key part value using bit32.bxor.
- The decrypted character is converted back to a string using string.char.
- The decrypted character is appended to the decrypted string.
- The keyIndex is incremented and wrapped around to 1 if it exceeds 3.
- Steps 2-7 are repeated for each character in the encrypted string.
- The final decrypted string is returned.
Example usage:โ
local encryptedStr = "Uryyb, jbeyq!"
local v3 = Vector3.new(1, 2, 3)
local decryptedStr = NFC:_dec(encryptedStr, v3)
print(decryptedStr)
NFC._dec = function(self, str: string, v3: Vector3)
local decrypted = ""
local keyIndex = 1
local key = {v3.X, v3.Y, v3.Z}
for i = 1, #str do
local char = string.byte(str, i)
local keyPart = key[keyIndex]
local decryptedChar = bit32.bxor(char, keyPart)
decrypted = decrypted .. string.char(decryptedChar)
keyIndex = keyIndex + 1
if keyIndex > 3 then
keyIndex = 1
end
end
return decrypted
end
๐ NFC Protocol Transmission & Receptionโ
๐ค Transmission (client1 -> server -> client1)โ
On the client-side (client1), the NFCt function is used to transmit NFC protocol messages to the server.
The function searches for a child object named "__rfidtag" within the tool handle part. If the child object is not found, it raises an assertion error and suggests creating it from the server.
The function constructs the data to be transmitted by concatenating the provided arguments and encrypts it using the _enc function.
It establishes a connection to the server-side RemoteEvent associated with "__rfidtag" and sends the encrypted data and the handle part as arguments through the server's FireServer method.
The function waits for a response by setting up a connection to the server's "OnClientEvent" event associated with "__rfidtag". Once the event is fired by the server, the transmitted data is sent.
After the transmission is completed, the connection is disconnected.
It is only natural to grant NFC transmission functionality to the client, as this allows the potential for realistic Flipper Zero-like devices to exist.
๐ฅ Reception (client2 -> server -> client1)โ
- The server establishes a connection to the "Touched" event of the handle part to listen for interactions with the NFC tag represented by the "__rfidtag" object.
- When the handle part is touched by another part in the game, the server checks if the touched part contains the "__rfidtag" object and if it is a RemoteEvent.
- If the conditions are met, the server establishes a connection to the server-side "OnServerEvent" of the "__rfidtag" RemoteEvent. This connection listens for incoming data from the client2 who touched the handle part.
- The server decrypts the received data using the _dec function.
- The server fires the decrypted data back to the original client (client1) using a RemoteEvent associated with "__rfidtag" through the server's FireClient method.
- A delay of 3 seconds is introduced to prevent rapid repeated interactions with the NFC tag.
- The server sets the flag variable ff back to false, allowing subsequent interactions to trigger the process again.