1- using System . Collections . Generic ;
1+ using MLAPI . NetworkingManagerComponents . Cryptography ;
2+ using System . Collections . Generic ;
23using System . Security . Cryptography ;
34using System . Text ;
45
@@ -15,44 +16,44 @@ public static ulong GetULongHash(string input, bool cache = false)
1516 if ( cache && ulongCachedHashes . ContainsKey ( input ) )
1617 return ulongCachedHashes [ input ] ;
1718
18- using ( SHA256Managed sha = new SHA256Managed ( ) )
19- {
20- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
21- ulong value = hash [ 0 ] | ( ( ulong ) hash [ 1 ] << 8 ) | ( ( ulong ) hash [ 2 ] << 16 ) | ( ( ulong ) hash [ 3 ] << 24 ) | ( ( ulong ) hash [ 4 ] << 32 ) | ( ( ulong ) hash [ 5 ] << 40 ) | ( ( ulong ) hash [ 6 ] << 48 ) | ( ( ulong ) hash [ 7 ] << 56 ) ;
19+ // using (SHA256Managed sha = new SHA256Managed())
20+ // {
21+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
22+ ulong value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastULong ( ) ; // hash[0] | ((ulong)hash[1] << 8) | ((ulong)hash[2] << 16) | ((ulong)hash[3] << 24) | ((ulong)hash[4] << 32) | ((ulong)hash[5] << 40) | ((ulong)hash[6] << 48) | ((ulong)hash[7] << 56);
2223 if ( cache )
2324 ulongCachedHashes . Add ( input , value ) ;
2425 return value ;
25- }
26+ // }
2627 }
2728
2829 public static ulong GetUIntHash ( string input , bool cache = false )
2930 {
3031 if ( cache && uintCachedHashes . ContainsKey ( input ) )
3132 return uintCachedHashes [ input ] ;
3233
33- using ( SHA256Managed sha = new SHA256Managed ( ) )
34- {
35- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
36- uint value = hash [ 0 ] | ( ( uint ) hash [ 1 ] << 8 ) | ( ( uint ) hash [ 2 ] << 16 ) | ( ( uint ) hash [ 3 ] << 24 ) ;
34+ // using (SHA256Managed sha = new SHA256Managed())
35+ // {
36+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
37+ uint value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastUInt ( ) ; // hash[0] | ((uint)hash[1] << 8) | ((uint)hash[2] << 16) | ((uint)hash[3] << 24);
3738 if ( cache )
3839 uintCachedHashes . Add ( input , value ) ;
3940 return value ;
40- }
41+ // }
4142 }
4243
4344 public static ushort GetUShortHash ( string input , bool cache = false )
4445 {
4546 if ( cache && ushortCachedHashes . ContainsKey ( input ) )
4647 return ushortCachedHashes [ input ] ;
4748
48- using ( SHA256Managed sha = new SHA256Managed ( ) )
49- {
50- byte [ ] hash = sha . ComputeHash ( Encoding . UTF8 . GetBytes ( input ) ) ;
51- ushort value = ( ushort ) ( hash [ 0 ] | ( ushort ) ( hash [ 1 ] << 8 ) ) ;
49+ // using (SHA256Managed sha = new SHA256Managed())
50+ // {
51+ // byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
52+ ushort value = MessageDigest . SHA1_Opt ( Encoding . UTF8 . GetBytes ( input ) ) . CastUShort ( ) ; // (ushort)(hash[0] | (ushort)(hash[1] << 8));
5253 if ( cache )
5354 ushortCachedHashes . Add ( input , value ) ;
5455 return value ;
55- }
56+ // }
5657 }
5758 }
5859}
0 commit comments