I'm trying to convert a C# script into Python. Here's what the C# Program looks like.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Encoder
{
public static string encodeLength(int value, int length)
{
string stack = "";
for (int x = 1; x <= length; x++)
{
int offset = 6 * (length - x);
byte val = (byte)(64 + (value >> offset & 0x3f));
stack += (char)val;
}
return stack;
}
public static string encodeLength(string Val)
{
int value = Val.Length;
int length = 2;
string stack = "";
for (int x = 1; x <= length; x++)
{
int offset = 6 * (length - x);
byte val = (byte)(64 + (value >> offset & 0x3f));
stack += (char)val;
}
return stack;
}
public static string encodeLength(int value)
{
int length = 2;
string stack = "";
for (int x = 1; x <= length; x++)
{
int offset = 6 * (length - x);
byte val = (byte)(64 + (value >> offset & 0x3f));
stack += (char)val;
}
return stack;
}
}
This is the stuff that I get returned when I call Encoder.encodeLength(55) + Encoder.encodeLength("Testing.".Length) + "Testing. in C#.
@w@HTesting.
Here's what I've written in Python so far.
def encodeLength(*args):
if len(args) == 2 and isinstance(args[0] and args[1], int):
i = 1
stack = str()
while (i <= length):
offset = 6 * (length - i)
x = 64 + (value >> offset & 0x3f)
stack += str(x)
i +=1
return stack
elif len(args) == 1 and isinstance(args[0], str):
i = 1
value = args[0]
length = 2
stack = str()
while (i <= length):
offset = 6 * (length - i)
x = 64 + (value >> offset & 0x3f)
stack += str(x)
i += 1
return stack
elif len(args) == 1 and isinstance(args[0], int):
i = 1
length = 2
stack = str()
while (i <= length):
offset = 6 * (length - i)
x = 64 + (args[0] >> offset & 0x3f)
stack += str(x)
i +=1
return stack
This is my response in Python when I call encodeLength(55) + encodeLength(len("Testing.")) + "Testing.".
641196472Testing.
Does anyone know why this isn't returning the output generated by C#?
lengthcome from?