Added PadMath page to test random number generation and correlation.

This commit is contained in:
Greg Edwards
2014-05-17 12:06:01 -04:00
parent 5f3e897c15
commit 66702d68e0
5 changed files with 113 additions and 1 deletions

View File

@@ -6,6 +6,6 @@
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<appSettings>
<add key="pkmnFoundationsBoxUpload4Dir" value="videos"/>
<add key="pkmnFoundationsBoxUpload4Dir" value="C:\Users\Greg\SkyDrive\Battle Videos G4"/>
</appSettings>
</configuration>

View File

@@ -59,6 +59,7 @@
<Content Include="BattleVideo.aspx" />
<Content Include="css\main.css" />
<Content Include="test\BoxUp.aspx" />
<Content Include="test\PadMath.aspx" />
<Content Include="test\Decode.aspx" />
<Content Include="Default.aspx" />
<Content Include="Global.asax" />
@@ -95,6 +96,13 @@
<Compile Include="test\BoxUp.aspx.designer.cs">
<DependentUpon>BoxUp.aspx</DependentUpon>
</Compile>
<Compile Include="test\PadMath.aspx.cs">
<DependentUpon>PadMath.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="test\PadMath.aspx.designer.cs">
<DependentUpon>PadMath.aspx</DependentUpon>
</Compile>
<Compile Include="test\Decode.aspx.cs">
<DependentUpon>Decode.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>

10
gts/test/PadMath.aspx Normal file
View File

@@ -0,0 +1,10 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="PadMath.aspx.cs" Inherits="PkmnFoundations.GTS.test.PadMath" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cpHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" runat="server">
<div class="code">
<asp:Literal ID="litRandom" runat="server" />
</div>
</asp:Content>

70
gts/test/PadMath.aspx.cs Normal file
View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace PkmnFoundations.GTS.test
{
public partial class PadMath : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileStream s = File.Open(Server.MapPath("~/Box Upload Xor Pad.bin"), FileMode.Open);
byte[] pad = new byte[s.Length];
s.Read(pad, 0, pad.Length);
s.Close();
byte[] result = new byte[256];
// difference between items
for (int x = 0; x < pad.Length; x++)
{
byte bx = (byte)x;
byte prevOffs = (byte)(bx - 4);
byte value = (byte)(((pad[bx] ^ pad[prevOffs]) & 0x80) > 0 ? 0xff : 0x00);
result[x] = value;
}
litRandom.Text = RenderHex(result.ToHexStringLower());
}
private String RenderHex(String hex)
{
StringBuilder builder = new StringBuilder();
for (int x = 0; x < hex.Length; x += 16)
{
if (x % 32 == 0)
{
builder.Append((x >> 1).ToString("x4"));
builder.Append(": ");
}
builder.Append(hex.Substring(x, Math.Min(16, hex.Length - x)));
builder.Append((x % 32 == 0) ? " " : "<br />");
}
return builder.ToString();
}
protected static int Rng1(int prev)
{
return (prev * 0x45 + 0x1111) & 0x7fffffff;
}
protected static int Rng2(int prev)
{
return (int)((0x41C64E6Du * (uint)prev) + 0x6073u);
}
protected static int Rng3(int prev)
{
return (int)((0x6C078965u * (uint)prev) + 0x1);
}
}
}

24
gts/test/PadMath.aspx.designer.cs generated Normal file
View File

@@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PkmnFoundations.GTS.test {
public partial class PadMath {
/// <summary>
/// litRandom control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litRandom;
}
}