You are here

public function MyLiveChat::MakeArray in My Live Chat 7

Same name and namespace in other branches
  1. 6 mylivechat.php \mylivechat::MakeArray()
1 call to MyLiveChat::MakeArray()
MyLiveChat::BasicEncrypt in ./mylivechat.php

File

./mylivechat.php, line 224
MyLiveChat module for Drupal

Class

MyLiveChat
@file MyLiveChat module for Drupal

Code

public function MakeArray($str, $random) {
  $len = pow(2, floor(log(strlen($str), 2)) + 1) + 8;
  if ($len < 32) {
    $len = 32;
  }
  $arr = array();
  $strarr = str_split($str);
  if ($random == TRUE) {
    for ($i = 0; $i < $len; $i++) {
      $arr[] = ord($strarr[rand() % strlen($str)]);
    }
    $start = 1 + rand() % ($len - strlen($str) - 2);
    for ($i = 0; $i < strlen($str); $i++) {
      $arr[$start + $i] = ord($strarr[$i]);
    }
    $arr[$start - 1] = 0;
    $arr[$start + strlen($str)] = 0;
  }
  else {
    for ($i = 0; $i < $len; $i++) {
      $arr[] = ord($strarr[$i % strlen($str)]);
    }
  }
  return $arr;
}