2009年01月10日
xorshiftの逆変換っす(2)
32bitバージョンでは上手くいったっす。
128bitバージョンでは連続4値でやれば分かるかもっす。
これはやってないので分かんないっす。
どうもぺんぎんっす( ◎v◎ )
関数を2つ用意したっす。
integer InvXORLeftshift(integer x, integer t)
integer InvXORRightshift(integer x, integer t)
InvXORLeftshift はx = x ^ (x << t) の逆変換、
InvXORRightshift はx = x ^ (x >> t) の逆変換っす。
これにxorshift_iの戻り値を入れてやるっす。
コードにあるtは13, 17, 5っす。
逆変換するときには逆順の5, 17, 13で入れるっす。
逆変換を実行するスクリプトではリンクメッセージで送られてきた
xorshift_i (integer)
処理前のx (string)
を使ってるっす。
コードのtouch_startイベントをいじってるっす。
touch_start(integer total_number)
{
string str_x = (string)x;
integer RNG_i = xorshift_i();
llMessageLinked(LINK_THIS, RNG_i, str_x,"");
}
上のように書き換えたコードと
下のスクリプトを同じプリムに入れてくださいっす。
///////////////////////
// The MIT Lisenses
// Copyright (c) 2009 Naoya Bellic
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////
//----------------
// ユーザ関数
//----------------
integer InvXORLeftshift(integer x, integer t) // x = x ^ (x << t) の逆変換
{
integer z = x; // xのコピー
integer s = (0x1 << t) -1;
integer r;
do
{
s = s << t;
r = z;
r = r << t;
r = r & s;
z = z ^ r;
}while((s & 0x80000000) == 0);
return z;
}
integer InvXORRightshift(integer x, integer t) // x = x ^ (x >> t) の逆変換
{
integer z = x; // xのコピー
integer s = (0x1 << t) -1 << 32-t;
integer r;
do
{
s = (s >> t) & ~((0x1 << t) -1 << 32-t);
r = z;
r = (r >> t) & ~((0x1 << t) -1 << 32-t);
r = r & s;
z = z ^ r;
}while((s & 0x1) == 0);
return z;
}
//***********
// state default
//***********
default
{
state_entry()
{
llSetText("xorshift_iの逆変換", <1.0, 1.0, 1.0>, 1.0);
}
link_message(integer sender_num, integer num, string str, key id)
{
integer inverse;
inverse = InvXORLeftshift(num, 5);
inverse = InvXORRightshift(inverse, 17);
inverse = InvXORLeftshift(inverse, 13);
llOwnerSay("\n" + "inverse:" + (string)inverse +"\n" + "x:" + (string)str);
}
}
128bitバージョンでは連続4値でやれば分かるかもっす。
これはやってないので分かんないっす。
どうもぺんぎんっす( ◎v◎ )
関数を2つ用意したっす。
integer InvXORLeftshift(integer x, integer t)
integer InvXORRightshift(integer x, integer t)
InvXORLeftshift はx = x ^ (x << t) の逆変換、
InvXORRightshift はx = x ^ (x >> t) の逆変換っす。
これにxorshift_iの戻り値を入れてやるっす。
コードにあるtは13, 17, 5っす。
逆変換するときには逆順の5, 17, 13で入れるっす。
逆変換を実行するスクリプトではリンクメッセージで送られてきた
xorshift_i (integer)
処理前のx (string)
を使ってるっす。
コードのtouch_startイベントをいじってるっす。
touch_start(integer total_number)
{
string str_x = (string)x;
integer RNG_i = xorshift_i();
llMessageLinked(LINK_THIS, RNG_i, str_x,"");
}
上のように書き換えたコードと
下のスクリプトを同じプリムに入れてくださいっす。
///////////////////////
// The MIT Lisenses
// Copyright (c) 2009 Naoya Bellic
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////
//----------------
// ユーザ関数
//----------------
integer InvXORLeftshift(integer x, integer t) // x = x ^ (x << t) の逆変換
{
integer z = x; // xのコピー
integer s = (0x1 << t) -1;
integer r;
do
{
s = s << t;
r = z;
r = r << t;
r = r & s;
z = z ^ r;
}while((s & 0x80000000) == 0);
return z;
}
integer InvXORRightshift(integer x, integer t) // x = x ^ (x >> t) の逆変換
{
integer z = x; // xのコピー
integer s = (0x1 << t) -1 << 32-t;
integer r;
do
{
s = (s >> t) & ~((0x1 << t) -1 << 32-t);
r = z;
r = (r >> t) & ~((0x1 << t) -1 << 32-t);
r = r & s;
z = z ^ r;
}while((s & 0x1) == 0);
return z;
}
//***********
// state default
//***********
default
{
state_entry()
{
llSetText("xorshift_iの逆変換", <1.0, 1.0, 1.0>, 1.0);
}
link_message(integer sender_num, integer num, string str, key id)
{
integer inverse;
inverse = InvXORLeftshift(num, 5);
inverse = InvXORRightshift(inverse, 17);
inverse = InvXORLeftshift(inverse, 13);
llOwnerSay("\n" + "inverse:" + (string)inverse +"\n" + "x:" + (string)str);
}
}
Posted by ぺんぎん at 02:08│Comments(0)
│スクリプト