Skip to content

Commit

Permalink
Merge pull request #2 from kapuragu/master
Browse files Browse the repository at this point in the history
GeoNameHash
  • Loading branch information
BobDoleOwndU authored Nov 25, 2023
2 parents aa55852 + 75f0561 commit e015dc8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 26 deletions.
6 changes: 5 additions & 1 deletion QuickHash/Hashing/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum HashType
String32 = 4,
ExtensionBytes = 5,
Fnv132 = 6,
GeoNameHash = 7,
} //HashType

public static string Convert(string text, int hashType, bool littleEndian, bool isDecimal)
Expand Down Expand Up @@ -38,7 +39,10 @@ public static string Convert(string text, int hashType, bool littleEndian, bool
result = (Hashing.HashFileExtension(text) << 3);
break;
case (int)HashType.Fnv132:
result = FnvHashManager.FNV1HashConvert(text.ToLower());
result = FnvHashManager.FNV1HashConvert(text);
break;
case (int)HashType.GeoNameHash:
result = GeoNameHash.GeoNameHashConvert(text);
break;
} //switch

Expand Down
2 changes: 1 addition & 1 deletion QuickHash/Hashing/FnvHashManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override byte[] HashFinal()
public static uint FNV1HashConvert(string text)
{
var fnvHash = new FNV1Hash32();
var value = fnvHash.ComputeHash(Encoding.UTF8.GetBytes(text));//DEBUGNOW encoding? -v-
var value = fnvHash.ComputeHash(Encoding.UTF8.GetBytes(text.ToLower()));//DEBUGNOW encoding? -v-
var hash = BitConverter.ToUInt32(value, 0);
return hash;
}//FNV1Hash32Str
Expand Down
21 changes: 21 additions & 0 deletions QuickHash/Hashing/GeoNameHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Linq;

namespace QuickHash.Hashing
{
public class GeoNameHash
{
//Reversed by Joey: https://discord.com/channels/364177293133873153/364178190588968970/893488488299757569
public static uint GeoNameHashConvert(string text)
{
uint nameLength = (uint)text.Length;
uint hash = nameLength;

for (int i = (int)(nameLength - 1); i >= 0; i--)
hash ^= text[i] + hash * 0x20 + (hash >> 2);
return hash;
}
}
}
3 changes: 2 additions & 1 deletion QuickHash/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 26 additions & 23 deletions QuickHash/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,32 @@ static void Main(string[] args)
text = args[0];

if (args.Length > 1)
switch (args[1])
{
case "-p64":
hashType = 0;
break;
case "-p64e":
hashType = 1;
break;
case "-s64":
hashType = 2;
break;
case "-p32":
hashType = 3;
break;
case "-s32":
hashType = 4;
break;
case "-e":
hashType = 5;
break;
case "-fnv32":
hashType = 6;
break;
switch (args[1].ToLower())
{
case "-p64":
hashType = 0;
break;
case "-p64e":
hashType = 1;
break;
case "-s64":
hashType = 2;
break;
case "-p32":
hashType = 3;
break;
case "-s32":
hashType = 4;
break;
case "-e":
hashType = 5;
break;
case "-fnv32":
hashType = 6;
break;
case "-geonamehash":
hashType = 7;
break;
} //switch

if (args.Length > 2)
Expand Down
1 change: 1 addition & 0 deletions QuickHash/QuickHash.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<ItemGroup>
<Compile Include="Hashing\FnvHashManager.cs" />
<Compile Include="Hashing\Converter.cs" />
<Compile Include="Hashing\GeoNameHash.cs" />
<Compile Include="Hashing\Hashing.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
Expand Down

0 comments on commit e015dc8

Please sign in to comment.