ソラマメブログ
プロフィール
ぺんぎん
ぺんぎん
どもっす( ◎v◎ )
ぺんぎんっす。

「ぺんぎんさん」でいいっす。
「ぺんさん」でもOKっすよ。
何だって良いんっすけどね。
[個体名:Naoya Bellic]
(非商用)
読者登録
メールアドレスを入力して登録する事で、このブログの新着エントリーをメールでお届けいたします。解除は→こちら
現在の読者数 1人

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);
  }
}




同じカテゴリー(スクリプト)の記事画像
位置判定っす
同じカテゴリー(スクリプト)の記事
 久しぶりの新関数っす (2011-04-23 23:19)
 11日(土)のオフィスアワーっす (2010-12-10 23:49)
 C#プロジェクトは凍結みたいっす (2010-07-01 22:35)
 4月24日のスクリプターズ・カフェっす (2010-04-27 19:06)
 潜入!1.38サーバーっす (2010-03-09 22:25)
 風の観測で分かったことっす (2009-08-16 22:11)

Posted by ぺんぎん at 02:08│Comments(0)スクリプト
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。