Created
August 25, 2016 14:48
-
-
Save KingCprey/3a6724b14c4ed97e0dbfc1f2bbc8e9ab to your computer and use it in GitHub Desktop.
Python script to create C# Hashing Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object_names=["md5","sha1","sha256","sha384","sha512"] | |
def getStrings(objname,access_modifier="public",modifier="static",include_buff=True,buffer_name="buff",include_offcount=True,buffer2_name="buff",buffer2_offset="offset",buffer2_count="count",include_strem=True,strem_name="strem",include_filepath=True,filepath_name="file_path",include_comment=True): | |
strs=[] | |
if not include_buff and include_offcount and include_strem and include_filepath:return strs | |
uppar=objname.upper() | |
if include_comment:strs.append("//%s"%uppar) | |
method_start="%s %s byte[] Get%s"%(access_modifier,modifier,uppar) | |
using_statement="using(%s %s=%s.Create())"%(uppar,objname,uppar) | |
if include_buff:strs.append(method_start+"(byte[] %s){%s{return %s.ComputeHash(%s);}}"%(buffer_name,using_statement,objname,buffer_name)) | |
if include_offcount:strs.append(method_start+"(byte[] %s,int %s,int %s){%s{return %s.ComputeHash(%s,%s,%s);}}"%(buffer2_name,buffer2_offset,buffer2_count,using_statement,objname,buffer2_name,buffer2_offset,buffer2_count)) | |
if include_strem:strs.append(method_start+"(Stream %s){%s{return %s.ComputeHash(%s);}}"%(strem_name,using_statement,objname,strem_name)) | |
if include_filepath:strs.append(method_start+"(string %s){using(FileStream fs=File.OpenRead(%s)){return Get%s(fs);}}"%(filepath_name,filepath_name,uppar)) | |
return strs | |
def printObjects(): | |
global object_names | |
for obj in object_names: | |
for s in getStrings(obj): | |
print(s) | |
printObjects() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment