Raised This Month: $51 Target: $400
 12% 

String Encrypting Method


Post New Thread Reply   
 
Thread Tools Display Modes
JusTGo
Veteran Member
Join Date: Mar 2013
Old 08-20-2017 , 08:02   Re: String Encrypting Method
Reply With Quote #11

Quote:
Originally Posted by siriusmd99 View Post
I don't need to convert it back. Just to get unique ID to save SQL.
Hash_column[0] = some hash
Hash_column[1] = some hash
And so on..
Then I read a text file and create an array to save hashes after I read string.
Like
fget string
Md5 hash
Str to num
And then save num to a global array
Hashes[i] = num

When player connects I get Hash_column from SQL and loop every ID to check if it's contained in Hashes[] global array.

So I just want str to num work without any engfunc and the generated integer id be unique so that there won't be different strings with same ID after using str to num. That's all.
why not just use steam id its unique and easy just one native call...
__________________
JusTGo is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-20-2017 , 08:10   Re: String Encrypting Method
Reply With Quote #12

I want to save weapon models to player in SQL. It's not efficient to save a string per weapon. That's why I want to get id of that string to save SQL. NO YOU UNDERSTAND?
siriusmd99 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-20-2017 , 08:36   Re: String Encrypting Method
Reply With Quote #13

MySQL does have a way to automatically generate unique IDs for you. Now if you only want to store some string in a database - go for it, there's nothing inefficient about it.

There's no way to get a 32bit integer of any string (this is what hashing is) without collision.
If you are actually looking at encryption - then it's not possible. You can't encrypt something and have shorter output than input.

Last edited by klippy; 08-20-2017 at 08:36.
klippy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-20-2017 , 12:39   Re: String Encrypting Method
Reply With Quote #14

There is no such thing as an ID of a string unless you are using a table that assigns a unique ID to each string. Therefore, it sounds more like you need to set up your database to do a many-to-many lookup (using multiple tables: one to store the weapon model strings and another to store the SteamID to string ID associations).

By saying "strings are inefficient" it likely means that you are trying way to hard to make trivial optimizations. When using SQL, the SQL queries are processed by the database itself and not the plugin running on your server.
__________________
fysiks is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-21-2017 , 12:12   Re: String Encrypting Method
Reply With Quote #15

Quote:
Originally Posted by siriusmd99 View Post
I want to save weapon models to player in SQL. It's not efficient to save a string per weapon.
Player can choose a model for each weapon in some skin menu? Hmm, this means that models already have an id. Or how player can choose models?
__________________

Last edited by PRoSToTeM@; 08-21-2017 at 12:13.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-21-2017 , 15:31   Re: String Encrypting Method
Reply With Quote #16

Quote:
Originally Posted by PRoSToTeM@ View Post
Player can choose a model for each weapon in some skin menu? Hmm, this means that models already have an id. Or how player can choose models?
LOL guys. You crawled so much into this problem. There doesn't matter what kind of problem do I have. I asked if I can generate an integer to make string unique, not to solve problem with weapons. I can do it already by assigning increment id to each model. I just wanted to know if there is any chance to generate integer hash.

P. S. every weapon can have more models like m4a1_red.mdl and m4a1_blue.mdl.
I didnt want to save skins as strings because if player has like 100 skins with length 64 then = 6400 length of SQL string. And I want to make more efficient and save space. If I saved integers ids instead then I would get only a string with length 100 but not 6400
siriusmd99 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-21-2017 , 15:50   Re: String Encrypting Method
Reply With Quote #17

Quote:
Originally Posted by siriusmd99 View Post
LOL guys. You crawled so much into this problem. There doesn't matter what kind of problem do I have.
We need to know the full context of your problem to find the best solution.
Quote:
Originally Posted by siriusmd99 View Post
I asked if I can generate an integer to make string unique, not to solve problem with weapons. I can do it already by assigning increment id to each model. I just wanted to know if there is any chance to generate integer hash.
If your model list is static then you can find hash function that will generate unique hashes for your strings.
Quote:
Originally Posted by siriusmd99 View Post
P. S. every weapon can have more models like m4a1_red.mdl and m4a1_blue.mdl.
If your models are always suffixed like "${default_model_path}_${suffix}.mdl" and suffix length is lower or equal 8 then you can store suffix in 64-bit number or in 32-bit number for length equal or lower 4.
Also, if suffix contains only a-zA-Z0-9 then you can store each char in 6 bits, so in 32-bit number you can store string with length equal 5 and 10 in 64-bit.
If suffix contains only a-z then you can store character in 5 bits.
6 a-z0-9 chars can be stored in 32-bit number.
__________________

Last edited by PRoSToTeM@; 08-21-2017 at 16:03.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-21-2017 , 16:37   Re: String Encrypting Method
Reply With Quote #18

Or just store those strings. 6400 is about 6 freaking kilobytes. You shouldn't worry about size until you get to gigabytes, it won't hinder performance.

Also you should normalize your database. Instead of repeating strings for every skin for every player, players should be an entity and weapon skins should be another one, then have a many-to-many relatioship between those two.
klippy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-21-2017 , 17:25   Re: String Encrypting Method
Reply With Quote #19

I can't do method with prefix because I want to make patch customizable and mobile.

Kippy, you mean creating a column for every weapon name and just add true or false to player?
So I if I have 100 skins then I will have 100 columns?
LOL. I see that weird.. Is this even possible to loop columns and get data on specified player?

Last edited by siriusmd99; 08-21-2017 at 17:27.
siriusmd99 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-21-2017 , 17:40   Re: String Encrypting Method
Reply With Quote #20

Quote:
Originally Posted by siriusmd99 View Post
you mean creating a column for every weapon name and just add true or false to player?
He means a table for skins with auto-increment id and model path. How to connect skins and players depends on how player can choose these skins. If player can choose skin for each weapon (some skin for ak47, another skin for m4a1) then you can implement it in several ways. For example, you can create another table which will store player id and 29 columns with skin id for each CS weapon. Or you can store player id, weapon id (which can be CSW_* or another table) and skin id.
__________________

Last edited by PRoSToTeM@; 08-21-2017 at 17:45.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode