• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:18
CET 19:18
KST 03:18
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Finals Preview: Arrival12TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9
Community News
BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION1Crank Gathers Season 2: SC II Pro Teams6Merivale 8 Open - LAN - Stellar Fest3Chinese SC2 server to reopen; live all-star event in Hangzhou22Weekly Cups (Oct 13-19): Clem Goes for Four3
StarCraft 2
General
Could we add "Avoid Matchup" Feature for rankgame RotterdaM "Serral is the GOAT, and it's not close" Smart servos says it affects liberators as well Chinese SC2 server to reopen; live all-star event in Hangzhou The New Patch Killed Mech!
Tourneys
Crank Gathers Season 2: SC II Pro Teams RSL Offline Finals Dates + Ticket Sales! Merivale 8 Open - LAN - Stellar Fest $5,000+ WardiTV 2025 Championship $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment
Brood War
General
[ASL20] Finals Preview: Arrival BSL Season 21 BSL Team A vs Koreans - Sat-Sun 16:00 CET ASL20 Pre-season Tier List ranking! ASL Runner-Up Race Stats
Tourneys
[ASL20] Grand Finals BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION ASL final tickets help [ASL20] Semifinal A
Strategy
Current Meta Soma's 9 hatch build from ASL Game 2 Simple Questions, Simple Answers Roaring Currents ASL final
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile General RTS Discussion Thread Nintendo Switch Thread Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread The Chess Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Korean Music Discussion Series you have seen recently... Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Benefits Of Limited Comm…
TrAiDoS
Sabrina was soooo lame on S…
Peanutsc
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1590 users

The Big Programming Thread - Page 784

Forum Index > General Forum
Post a Reply
Prev 1 782 783 784 785 786 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
shz
Profile Blog Joined October 2010
Germany2687 Posts
October 20 2016 21:17 GMT
#15661
On October 21 2016 06:16 Manit0u wrote:
Show nested quote +
On October 21 2016 00:20 Djagulingu wrote:
Windows has one good thing going for it and that's Windows Media Player. No matter what everyone says, Windows is the more friendly OS (out of what I've used ofc, never used Mac so it might also be more friendly) if you have a few gigs of mp3s and want to listen to them. The only good music player Ubuntu has is Clementine and it's fucking unpredictable as fuck.


First, if you're using anything other than Foobar for music listening in Windows you're misguided


[image loading]
Liquipedia
Prillan
Profile Joined August 2011
Sweden350 Posts
October 20 2016 21:18 GMT
#15662
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?


final public static function encrypt($data)
{
$serialized = serialize($data);

$iv = static::getIv();
$key = static::getKey();
$mac = static::getMac($serialized, $key);

$serialized .= $mac;

$passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $serialized, MCRYPT_MODE_CBC, $iv);

return sprintf('%s|%s', base64_encode($passcrypt), base64_encode($iv));
}

final public static function decrypt($data)
{
$key = static::getKey();
$decrypt = explode('|', $data);

if (count($decrypt) !== 2) {
return false;
}

$decoded = base64_decode($decrypt[0]);
$iv = base64_decode($decrypt[1]);

if (!static::validIv($iv)) {
return false;
}

$decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv));

if (!static::validMac($decrypted, $key)) {
return false;
}

return unserialize(substr($decrypted, 0, -64));
}

final public static function getIvSize()
{
return mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
}

final public static function getIv()
{
return mcrypt_create_iv(static::getIvSize(), MCRYPT_DEV_URANDOM);
}

final public static function validIv($iv)
{
return strlen($iv) === static::getIvSize();
}

final public static function getMac($data, $key)
{
return hash_hmac('sha256', $data, substr(bin2hex($key), -32));
}

final public static function validMac($decrypted, $key)
{
return substr($decrypted, -64) === static::getMac(substr($decrypted, 0, -64), $key);
}

final public static function getPublicKey()
{
return static::generateRandomKey(); // obviously there's something else here (doesn't return random key)
}

final public static function getPrivateKey()
{
return static::generateRandomKey(); // obviously there's something else here (doesn't return random key)
}

final public static function getKey()
{
$compositeKey = static::getPublicKey();
$compositeKey .= static::getPrivateKey();

return pack('H*', hash('sha256', $compositeKey));
}

final public static function generateRandomKey()
{
return md5(uniqid(mt_rand(), true)); // to illustrate sample keys
}


The encryption has to be based on 2 separate keys. One is per-application and the other one is per-client, ensuring that even if you get a hold of one key it's no good. Getting hold on both keys in one system doesn't compromise other systems.

Cool thing about it is that it allows you to encrypt not just text but even arrays and objects (which turn into fully functional PHP arrays/objects upon decryption). Which can let you for example send objects (of specific class with their fields set) through some API and share them between systems.

The cryptography does look sound, but I might have missed something. I'm more worried about using serialize and unserialize. I'm not a PHP programmer but I'm pretty sure that one can use unserialize to trigger internal methods during deserialization that can let an attacker run arbitrary code. Unfortunately, I don't remember when and where I read this.
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
tofucake
Profile Blog Joined October 2009
Hyrule19149 Posts
October 20 2016 21:38 GMT
#15663
unserialize in PHP is horribly unsafe

also, mcrypt is abandoned and has been deprecated for 7.1. You should probably use openssl or an encryption library
Liquipediaasante sana squash banana
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
Last Edited: 2016-10-20 23:18:58
October 20 2016 22:11 GMT
#15664
On October 21 2016 06:38 tofucake wrote:
unserialize in PHP is horribly unsafe

also, mcrypt is abandoned and has been deprecated for 7.1. You should probably use openssl or an encryption library


Wow, good to know

Man, it sucks to be working on software that has to run on servers where the highest PHP version is 5.3...
Time is precious. Waste it wisely.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
Last Edited: 2016-10-21 06:30:43
October 21 2016 06:22 GMT
#15665
On October 21 2016 00:45 Morfildur wrote:
Linux doesn't have a native ssh or sftp client nor a C++ compiler. Pretty much all distributions include those, but they are not included in Linux by default. If you bootstrap your own Linux, which I actually did a few years back, you have to install all of those on your own. You are confusing Linux with Linux distributions. Also, those are hardly things a normal user requires.

I don't want to bootstrap my own Linux because I don't need to bootstrap my own Linux. I just need to be able to develop and test on my local machine, with my app having the same behavior as it will have on my ec2 instances. Ubuntu 16.04 gives me that (my ec2 instances are 14.04, but still), Windows dies trying.

On October 21 2016 00:45 Morfildur wrote:
As for hiding files, I found Linux to be a bigger pain. Some files are in /usr/bin, /usr/lib, /usr/local/bin, /usr/local/lib, /usr/include, /usr/local/include, /opt (Debian based distributions -.-), /etc, /var, ... and a lot of distributions have their own layout, e.g. apache config on RedHat based distributions is in /etc/httpd, because apache is the company and httpd the product, on Debian based distributions it's /etc/apache2, because Debian users are stupidmisguided, ... and god help you if you want to install something that doesn't have a native package for your specific distribution. Most desktop distributions these days aren't even actually safer, because they have the default user in sudoer without password or use root without a password, because they noticed that people don't actually want to be bothered by having to enter a password for what they consider simple things.

At least you have autoremove coming with Ubuntu for deleting "secret and unneeded files". Also, if you want to make Ubuntu safer, you can. There is no way to make Windows safer. No amount of passwords and shit.

On October 21 2016 02:31 spinesheath wrote:
Show nested quote +
On October 21 2016 00:20 Djagulingu wrote:
- Windows doesn't have and never had a native ssh client
- The most popular ssh client for windows can't even use keys with .pem extension
- Windows doesn't have and never had a native sftp client
- The most popular sftp client for windows wants to get updated every other day
- The most popular sftp client for windows needs to get updated every other day
- The most popular sftp client for windows can't even use keys with .pem extension
- At least 50% of the node packages doesn't work on windows (the number grows up to 100% for geospatial packages)
- Windows doesn't even have a native C++ compiler
- The previous thing is fucking the thing that's before him right in the butt
- Windows doesn't even have docker natively (you fucking need a VM just to use Docker)
- Windows fucking hides your files everywhere in the file system and you don't even have a control over it. One minute you need to install a few things just to get something work and next thing you know, you only have 20 gigs of free disk space.
- Regarding the previous point: You need to install a metric fuckton of shit just to get stuff working
- Don't even bother installing apache web server or postgresql or some other shit on Windows. Windows will lose all your disk space and never give it back.

Those clearly are mighty important for the average user.

I used Ubuntu a bunch during my time at uni. I had my fair share of problems with both Ubuntu and Windows. Windows still is more convenient for the stuff I usually do.

It would still take a company like Microsoft no time to write 2 tools that can accomplish the functionality of:

1- ssh -i key.pem user@remoteserveraddress
2- sftp -i key.pem user@remoteserveraddress

They say they will try to make Windows a better experience for developers too, but I'm still not seeing an ssh client.
"windows bash is a steaming heap of shit" tofucake
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-10-21 07:39:24
October 21 2016 07:23 GMT
#15666
--- Nuked ---
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 21 2016 08:50 GMT
#15667
On October 21 2016 16:23 Nesserev wrote:
Show nested quote +
On October 21 2016 15:22 Djagulingu wrote:
It would still take a company like Microsoft no time to write 2 tools that can accomplish the functionality of:

1- ssh -i key.pem user@remoteserveraddress
2- sftp -i key.pem user@remoteserveraddress

They say they will try to make Windows a better experience for developers too, but I'm still not seeing an ssh client.

Actually, it would probably take years, result in a closed proprietary product accompanied by a large book of documentation filled with weird quirks, ugly hacks and backwards logic.

Yeah, you're probably right. I forgot that the tool will be developed by the same guys who developed Windows, so the lack of developer skill is to be taken into account.

Onto the music player thing, I found Clementine to be the best one and I tried VLC and Amarok too. I find Windows Media Player good too, so feel free to ignore what I say about Music players and think that I'm a dipshit for thinking that way.
"windows bash is a steaming heap of shit" tofucake
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 21 2016 09:33 GMT
#15668
On October 21 2016 17:50 Djagulingu wrote:
Show nested quote +
On October 21 2016 16:23 Nesserev wrote:
On October 21 2016 15:22 Djagulingu wrote:
It would still take a company like Microsoft no time to write 2 tools that can accomplish the functionality of:

1- ssh -i key.pem user@remoteserveraddress
2- sftp -i key.pem user@remoteserveraddress

They say they will try to make Windows a better experience for developers too, but I'm still not seeing an ssh client.

Actually, it would probably take years, result in a closed proprietary product accompanied by a large book of documentation filled with weird quirks, ugly hacks and backwards logic.

Yeah, you're probably right. I forgot that the tool will be developed by the same guys who developed Windows, so the lack of developer skill is to be taken into account.

Onto the music player thing, I found Clementine to be the best one and I tried VLC and Amarok too. I find Windows Media Player good too, so feel free to ignore what I say about Music players and think that I'm a dipshit for thinking that way.


Microsoft is the company that developed C# and .NET, which is the best programming language and Framework I've ever worked with and the Visual Studio IDE that is currently unmatched, and I've worked with pretty much any programming language of the past 20 years, a few dozen frameworks and an endless amount of terrible IDEs. They do have some amazing developers, they are just held back by some stupid decisions from marketing, e.g. windows store and all that.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
Last Edited: 2016-10-21 09:39:41
October 21 2016 09:39 GMT
#15669
On October 21 2016 18:33 Morfildur wrote:
Show nested quote +
On October 21 2016 17:50 Djagulingu wrote:
On October 21 2016 16:23 Nesserev wrote:
On October 21 2016 15:22 Djagulingu wrote:
It would still take a company like Microsoft no time to write 2 tools that can accomplish the functionality of:

1- ssh -i key.pem user@remoteserveraddress
2- sftp -i key.pem user@remoteserveraddress

They say they will try to make Windows a better experience for developers too, but I'm still not seeing an ssh client.

Actually, it would probably take years, result in a closed proprietary product accompanied by a large book of documentation filled with weird quirks, ugly hacks and backwards logic.

Yeah, you're probably right. I forgot that the tool will be developed by the same guys who developed Windows, so the lack of developer skill is to be taken into account.

Onto the music player thing, I found Clementine to be the best one and I tried VLC and Amarok too. I find Windows Media Player good too, so feel free to ignore what I say about Music players and think that I'm a dipshit for thinking that way.

Microsoft is the company that developed C# and .NET, which is the best programming language and Framework I've ever worked with and the Visual Studio IDE that is currently unmatched, and I've worked with pretty much any programming language of the past 20 years, a few dozen frameworks and an endless amount of terrible IDEs..

I hope you mean VS + Resharper right?

Vanilla VS is makes me wanna cry when I have to use that shit again.
The harder it becomes, the more you should focus on the basics.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 21 2016 10:51 GMT
#15670
On October 21 2016 18:33 Morfildur wrote:
Show nested quote +
On October 21 2016 17:50 Djagulingu wrote:
On October 21 2016 16:23 Nesserev wrote:
On October 21 2016 15:22 Djagulingu wrote:
It would still take a company like Microsoft no time to write 2 tools that can accomplish the functionality of:

1- ssh -i key.pem user@remoteserveraddress
2- sftp -i key.pem user@remoteserveraddress

They say they will try to make Windows a better experience for developers too, but I'm still not seeing an ssh client.

Actually, it would probably take years, result in a closed proprietary product accompanied by a large book of documentation filled with weird quirks, ugly hacks and backwards logic.

Yeah, you're probably right. I forgot that the tool will be developed by the same guys who developed Windows, so the lack of developer skill is to be taken into account.

Onto the music player thing, I found Clementine to be the best one and I tried VLC and Amarok too. I find Windows Media Player good too, so feel free to ignore what I say about Music players and think that I'm a dipshit for thinking that way.


Microsoft is the company that developed C# and .NET, which is the best programming language and Framework I've ever worked with and the Visual Studio IDE that is currently unmatched, and I've worked with pretty much any programming language of the past 20 years, a few dozen frameworks and an endless amount of terrible IDEs. They do have some amazing developers, they are just held back by some stupid decisions from marketing, e.g. windows store and all that.

Then they should transfer their incredibly talented developers to the Windows team, fire all marketing guys who work on windows and never hire replacements, wait for it and then we might finally have a Windows version which can finally stop losing the OS war against Linux.
"windows bash is a steaming heap of shit" tofucake
Khalum
Profile Joined September 2010
Austria831 Posts
October 21 2016 10:54 GMT
#15671
It's getting better though, not worse.
R1CH
Profile Blog Joined May 2007
Netherlands10341 Posts
October 21 2016 11:56 GMT
#15672
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?


Don't touch anything except libsodium.

https://github.com/jedisct1/libsodium-php
AdministratorTwitter: @R1CH_TL
Prillan
Profile Joined August 2011
Sweden350 Posts
October 21 2016 12:45 GMT
#15673
On October 21 2016 20:56 R1CH wrote:
Show nested quote +
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?


Don't touch anything except libsodium.

https://github.com/jedisct1/libsodium-php

Care to elaborate?

"Sodium is a new, easy-to-use software library for encryption, decryption, signatures, password hashing and more."

New is usually a property that should be avoided when doing cryptography. But on the other hand, PHP is bad in so many regards that they might have failed at building good cryptographic constructs to begin with.
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
Last Edited: 2016-10-21 13:50:37
October 21 2016 13:14 GMT
#15674
On October 21 2016 18:33 Morfildur wrote:
Microsoft is the company that developed C# and .NET, which is the best programming language and Framework I've ever worked with and the Visual Studio IDE that is currently unmatched, and I've worked with pretty much any programming language of the past 20 years, a few dozen frameworks and an endless amount of terrible IDEs. They do have some amazing developers, they are just held back by some stupid decisions from marketing, e.g. windows store and all that.


Would you care to elaborate a bit on why do you find C# and .NET the best?

I know it's nice and my limited experience with it was quite pleasant but it didn't seriously "wow" me as much as Scala or Ruby did. It might be because I've never really done anything big in any of those languages, or never had to work for extended time with them but they seemed like they were some seriously next level stuff.

On October 21 2016 20:56 R1CH wrote:
Show nested quote +
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?


Don't touch anything except libsodium.

https://github.com/jedisct1/libsodium-php


I'd love to use libsodium but I can't for this. 90% of our clients are city halls and such, which means that their servers are crap, their admins don't know what they're doing and there's close to no chance at all of compiling/installing any new software in there. I mean, the best server they have is running PHP 5.3 and is some old Cent OS crap.

The most laughable thing we've noticed on their servers was top of the line firewall and web filter but they only had one rule in it "allow all for all". It's pathetic but I guess it all boils down to how much is government willing to pay their employees and you simply can't get a good admin with such low pay.
Time is precious. Waste it wisely.
Mr. Wiggles
Profile Blog Joined August 2010
Canada5894 Posts
October 21 2016 13:17 GMT
#15675
On October 21 2016 21:45 Prillan wrote:
Show nested quote +
On October 21 2016 20:56 R1CH wrote:
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?


Don't touch anything except libsodium.

https://github.com/jedisct1/libsodium-php

Care to elaborate?

"Sodium is a new, easy-to-use software library for encryption, decryption, signatures, password hashing and more."

New is usually a property that should be avoided when doing cryptography. But on the other hand, PHP is bad in so many regards that they might have failed at building good cryptographic constructs to begin with.

Sodium is built using NaCl ( http://nacl.cr.yp.to ) which is ~8 years old. It's also relatively battle-tested: https://download.libsodium.org/doc/libsodium_users/

Note that the project is about 3 years old, so it's not "new".

On another note, I'm doubtful any programming language provides a good cryptography implementation out of the box.
you gotta dance
phar
Profile Joined August 2011
United States1080 Posts
October 22 2016 18:13 GMT
#15676
On October 20 2016 22:21 Manit0u wrote:
Is anyone here good with cryptography?

I'm wondering if such code would be sufficient to encode/decode some sensitive data?

The encryption has to be based on 2 separate keys. One is per-application and the other one is per-client, ensuring that even if you get a hold of one key it's no good. Getting hold on both keys in one system doesn't compromise other systems.

Cool thing about it is that it allows you to encrypt not just text but even arrays and objects (which turn into fully functional PHP arrays/objects upon decryption). Which can let you for example send objects (of specific class with their fields set) through some API and share them between systems.

Depends on your definition of "good". I learned enough in Uni and on the job to know that rule #1 is:

Don't ever do your own crypto, unless you really are an expert. It will end badly.

Even if you're going to use someone else's crypto library, stop and ask an expert.

Shit is too hard, way too easy to mess up, and the consequences are too big.


Some few thoughts from reading your code:

Check all those libraries you're using, chances are some of them are not appropriate for crypto. Especially check anything you use to generate a 'random', as the requirements for crypto strength random are way, way, way more stringent.
Who after all is today speaking about the destruction of the Armenians?
Hhanh00
Profile Joined May 2016
34 Posts
October 23 2016 01:30 GMT
#15677
The 'random' part is a placeholder for code that he means to replace with something better.

@OP, your code seems fine but uses algo that aren't common. It is bound to raise some questions.
1. The session key is hash(k1|k2). Assuming k1 and k2 have enough entropy, sk is ok but why not use a standard key derivation scheme instead?
2. You use MCRYPT_RIJNDAEL_256. I'm not sure if it's on purpose but if you intended to do AES-256, you should use MCRYPT_RIJNDAEL_128. 128 refers to the block size and not the key size.
3. mcrypt pads with 0 if the data isn't a multiple of the block size. If your data can have trailing \0, this could be problematic.
4. You have mac on plain text then encrypt. That doesn't protect the ciphertext. The recommended way is to encrypt and then add mac on ciphertext.

Disclaimer: I know next to nothing about PHP so I can't comment on that and I'm not an expert in crypto either.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-10-23 17:54:13
October 23 2016 17:35 GMT
#15678
Okay let's say I was using a set to store objects.
And, if I wanted to store a repeat of the same object, I wanted to increase some sort of count that said "now you're storing 2 of those objects". So Let's say if I added "3, 4, 4, 4, 3" to the bag, I would be able to see "3" and "4" in the bag, and somehow have a count that could tell me that there was 2 3s, and 3 4s.

How could I do that in java?




edit: what is coming to my mind first is putting the items into an array of size 2, where one of the indexes is the object and the other index is the number of the objects

and then putting the arrays into the set


edit: or I guess I could make a new class that has the object and the count and add that into the set?
JWD[9]
Profile Blog Joined November 2015
364 Posts
Last Edited: 2016-10-23 18:00:01
October 23 2016 17:57 GMT
#15679
On October 24 2016 02:35 travis wrote:
Okay let's say I was using a set to store objects.
And, if I wanted to store a repeat of the same object, I wanted to increase some sort of count that said "now you're storing 2 of those objects". So Let's say if I added "3, 4, 4, 4, 3" to the bag, I would be able to see "3" and "4" in the bag, and somehow have a count that could tell me that there was 2 3s, and 3 4s.

How could I do that in java?




edit: what is coming to my mind first is putting the items into an array of size 2, where one of the indexes is the object and the other index is the number of the objects

and then putting the arrays into the set


edit: or I guess I could make a new class that has the object and the count and add that into the set?


I don't know Java. In C++ you could do a class with a static variable ( a variable that is shared between all objects of the class ). If you were to do the arrays, than in C++ you would rather use lists than arrays, since arrays elements have to be next to each other in memory, and if you have a set of arrays, you'd have to move all elements of the set in order to extend one array, while with a list, you just have a set of pointers to the first element of the lists, and new elements can go anywhere.

Edit: NVM, read your array idea wrong. that sounds like the same as making an object with a counter, make the object in that case.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 23 2016 18:08 GMT
#15680
--- Nuked ---
Prev 1 782 783 784 785 786 1032 Next
Please log in or register to reply.
Live Events Refresh
Monday Night Weeklies
17:00
Open Cup
RotterdaM543
TKL 310
IndyStarCraft 228
SteadfastSC196
ZombieGrub93
BRAT_OK 62
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 543
mouzHeroMarine 459
TKL 310
IndyStarCraft 228
SteadfastSC 196
UpATreeSC 100
ZombieGrub93
ProTech84
MaxPax 74
BRAT_OK 62
MindelVK 28
StarCraft: Brood War
Britney 21552
Sea 638
Yoon 363
Rock 54
Dewaltoss 37
yabsab 20
Dota 2
qojqva4220
Dendi1196
BananaSlamJamma252
PGG 89
Counter-Strike
fl0m2522
ScreaM1151
FunKaTv 64
Other Games
FrodaN1616
Beastyqt562
ceh9443
Lowko291
Liquid`VortiX219
mouzStarbuck210
B2W.Neo153
ArmadaUGS124
C9.Mang079
Mew2King74
QueenE62
rGuardiaN44
Organizations
Counter-Strike
PGL11530
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• kabyraGe 105
• iHatsuTV 6
• Reevou 2
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• IndyKCrew
StarCraft: Brood War
• HerbMon 41
• FirePhoenix10
• Michael_bg 4
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2788
League of Legends
• Nemesis3464
• imaqtpie1977
• TFBlade833
Other Games
• WagamamaTV415
• Shiphtur103
Upcoming Events
BSL 21
6h 42m
Replay Cast
15h 42m
Streamerzone vs Shopify Rebellion
Streamerzone vs Team Vitality
Shopify Rebellion vs Team Vitality
WardiTV Invitational
17h 42m
CrankTV Team League
18h 42m
BASILISK vs TBD
Team Liquid vs Team Falcon
BSL 21
1d 6h
Replay Cast
1d 15h
BASILISK vs TBD
Team Liquid vs Team Falcon
OSC
1d 17h
CrankTV Team League
1d 18h
Replay Cast
2 days
The PondCast
2 days
[ Show More ]
CrankTV Team League
2 days
Replay Cast
3 days
WardiTV Invitational
3 days
CrankTV Team League
3 days
Replay Cast
4 days
BSL Team A[vengers]
4 days
Dewalt vs Shine
UltrA vs ZeLoT
BSL 21
5 days
Sparkling Tuna Cup
5 days
BSL Team A[vengers]
5 days
Cross vs Motive
Sziky vs HiyA
BSL 21
6 days
Wardi Open
6 days
Liquipedia Results

Completed

ASL Season 20
WardiTV TLMC #15
Eternal Conflict S1

Ongoing

BSL 21 Points
CSL 2025 AUTUMN (S18)
BSL 21 Team A
C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
CranK Gathers Season 2: SC II Pro Teams
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025

Upcoming

SC4ALL: Brood War
YSL S2
BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
META Madness #9
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.