Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences

anonymous No title
JavaScript
import { DateTime } from 'luxon';
import { Container, Table } from 'react-bootstrap';
import { useState } from 'react';

interface Props {
  year?: number;
  month?: number;
};

export default function Calendar(props: Props) {
  let { year, month } = props;
  if (!year) year = DateTime.local().year;
  if (!month) month = DateTime.local().month;

  const firstDayOfThisMonth = DateTime.local(year, month, 1, 0, 0);
  const firstWeekDay = firstDayOfThisMonth.weekday;

  const firstDayLocation = (() => {
    switch (firstWeekDay) {
      case 1:
        return 2;
      case 2:
        return 3;
      case 3:
        return 4;
      case 4:
        return 5;
      case 5:
        return 6;
      case 6:
        return 7;
      case 7:
        return 1;
      default:
        return 1;
    }
  })();

  const daysOfMonth = (() => {
    if (month === 2) {
      if (year % 4 === 0) {
        if (year % 100 === 0 && year % 400 !== 0) {
          return 29;
        } else {
          return 28;
        }
      }
    } else if (month === 4 || month === 6 || month === 9 || month === 11) {
      return 30;
    } else {
      return 31;
    }
  })();

  interface Day {
    dateNum?: number;
  }

  const daysOfCalendar = (() => {
    const sixWeek = [];
    let dayCount = 1;
    const firstWeek = [];
    for (let i = 1; i <= 7; i++) {
      const day: Day = {};
      if (i >= firstDayLocation) {
        day.dateNum = dayCount;
        dayCount++;
      }
      firstWeek.push(day);
    }
    sixWeek.push(firstWeek);

    for (let i = 0; i < 5; i++) {
      const week = [];
      for (let i = 0; i < 7; i++) {
        const day: Day = {};
        if (dayCount <= daysOfMonth!) {
          day.dateNum = dayCount;
          dayCount++;
        }
        week.push(day)
      }
      sixWeek.push(week);
    }
    return sixWeek;
  })();
  console.log(daysOfCalendar)


  const [ schedules ] = useState(daysOfCalendar);

  function createDays() {
    return (schedules.map(scheduleArray => (
      <tr>
        {
          scheduleArray.map(day => (
            <td>{day.dateNum}</td>
          ))
        }
      </tr>
    )));
  }

  return (
    <Container>
      <Table className='table-bordered'>
        <thead>
          <tr>
            <th>日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th>土</th>
          </tr>
        </thead>
        <tbody>
          {createDays()}
        </tbody>
      </Table>
    </Container>
  );
}





export enum WeekDay {
  Sunday,
  Monday,
  Tuesday,
  Wednesday,
  Thursday,
  Friday,
  Saturday
}

anonymous No title
PHP
logoHarigami
ログイン
 anonymous タイトルなし No License PHP
 コピー
<?php
namespace smo\WarnSystem;
use pocketmine\plugin\PluginBase;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\Player;
use pocketmine\utils\Config;
class Main extends PluginBase implements Listener{
	/*
	 * Config保存の方法:
	 *
	 * ・N === 警告なし
	 * ・1 === 警告一個 (⚠)
	 * ・2 === 警告二個 (⚠⚠)
	 * ・3 === 警告三個 (⚠⚠⚠)
	 */
	private function setWarnTag(Player $player, WarnPoint $p) :void{
		switch($p){
			case 1:
			$player->setNameTag("§c⚠§r".$name);
			$player->setDisplayName("§c⚠§r".$name);
			$player->save();
			break;
			case 2:
			$player->setNameTag("§c⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠§r".$name);
			$player->save();
			break;
			case 3:
			$player->setNameTag("§c⚠⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠⚠§r".$name);
			$player->save();
			break;
		}
	}
	public function onEnable() :void{
		$this->getLogger()->notice("WarnSystemを読み込みました by smo");
		$this->getServer()->getPluginManager()->registerEvents($this, $this);
		if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0744, true);
						$this->c = new Config($this->getDataFolder() . "config.yml", Config::YAML);
	}
	/**
 * @priority MONITOR
 */
	public function onJoin(PlayerJoinEvent $event) :void{
		$player = $event->getPlayer();
		$name = $event->getPlayer()->getName();
		if(!$this->c->exists($name)) {
			$this->c->set($name, "N");
			$this->c->save();
		}else{
			switch($this->c->get($name)){
				case "N":
				break;
				case "1":
				$this->setWarnTag($player, 1);
				break;
				case "2":
				$this->setWarnTag($player, 2);
				break;
				case "3":
				$this->setWarnTag($player, 3);
				break;
			}
		}
		public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
			switch($command->getName()){
				case "checkwarn":
				if(!$sender instanceof Player){
					$sender->sendMessage("§6>>§cゲーム内で実行してください");
				}else{
					switch($this->c->get($sender->getName())){
						case "N":
						$sender->sendMessage("§6>>§aあなたは警告されていません");
						break;
						case "1":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e1§cです");
						break;
						case "2":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e2§cです");
						break;
						case "3":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e3§cです");
						break;
					}
				}
				break;
				case "warn":
				if(!isset($args[0])) return false;
				if(!issrt($args[1])) return false;
				switch($args[0]){
					case "add":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e3§aにしました");
						$this->c->set($args[1], "3");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§cの累積警告は既に最大値です");
					}
					break;
					case "remove":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§cは警告されていません");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を取り消しました");
						$this->c->set($args[1], "N");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}
					break;
					case "check":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§eなし");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e1");
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e2");
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e3");
					}
					break;
				}
				break;
			}
			return true;
		}
	}
}

anonymous No title
PHP
logoHarigami
ログイン
 anonymous タイトルなし No License PHP
 コピー
<?php
namespace smo\WarnSystem;
use pocketmine\plugin\PluginBase;
use pocketmine\command\CommandSender;
use pocketmine\command\Command;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\Player;
use pocketmine\utils\Config;
class Main extends PluginBase implements Listener{
	/*
	 * Config保存の方法:
	 *
	 * ・N === 警告なし
	 * ・1 === 警告一個 (⚠)
	 * ・2 === 警告二個 (⚠⚠)
	 * ・3 === 警告三個 (⚠⚠⚠)
	 */
	private function setWarnTag(Player $player, WarnPoint $p) :void{
		switch($p){
			case 1:
			$player->setNameTag("§c⚠§r".$name);
			$player->setDisplayName("§c⚠§r".$name);
			$player->save();
			break;
			case 2:
			$player->setNameTag("§c⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠§r".$name);
			$player->save();
			break;
			case 3:
			$player->setNameTag("§c⚠⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠⚠§r".$name);
			$player->save();
			break;
		}
	}
	public function onEnable() :void{
		$this->getLogger()->notice("WarnSystemを読み込みました by smo");
		$this->getServer()->getPluginManager()->registerEvents($this, $this);
		if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0744, true);
						$this->c = new Config($this->getDataFolder() . "config.yml", Config::YAML);
	}
	/**
 * @priority MONITOR
 */
	public function onJoin(PlayerJoinEvent $event) :void{
		$player = $event->getPlayer();
		$name = $event->getPlayer()->getName();
		if(!$this->c->exists($name)) {
			$this->c->set($name, "N");
			$this->c->save();
		}else{
			switch($this->c->get($name)){
				case "N":
				break;
				case "1":
				$this->setWarnTag($player, 1);
				break;
				case "2":
				$this->setWarnTag($player, 2);
				break;
				case "3":
				$this->setWarnTag($player, 3);
				break;
			}
		}
		public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
			switch($label){
				case "checkwarn":
				if(!$sender instanceof Player){
					$sender->sendMessage("§6>>§cゲーム内で実行してください");
				}else{
					switch($this->c->get($sender->getName())){
						case "N":
						$sender->sendMessage("§6>>§aあなたは警告されていません");
						break;
						case "1":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e1§cです");
						break;
						case "2":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e2§cです");
						break;
						case "3":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e3§cです");
						break;
					}
				}
				break;
				case "warn":
				if(!isset($args[0])) return false;
				if(!issrt($args[1])) return false;
				switch($args[0]){
					case "add":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e3§aにしました");
						$this->c->set($args[1], "3");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§cの累積警告は既に最大値です");
					}
					break;
					case "remove":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§cは警告されていません");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を取り消しました");
						$this->c->set($args[1], "N");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}
					break;
					case "check":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§eなし");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e1");
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e2");
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e3");
					}
					break;
				}
				break;
			}
			return true;
		}
	}
}

anonymous No title
PHP
<?php

namespace smo\WarnSystem;

use pocketmine\plugin\PluginBase;

use pocketmine\command\CommandSender;
use pocketmine\command\Command;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;

use pocketmine\Player;

use pocketmine\utils\Config;

class Main extends PluginBase implements Listener{

	/*
	 * Config保存の方法:
	 *
	 * ・N === 警告なし
	 * ・1 === 警告一個 (⚠)
	 * ・2 === 警告二個 (⚠⚠)
	 * ・3 === 警告三個 (⚠⚠⚠)
	 */

	private function setWarnTag(Player $player, WarnPoint $p) :void{
		switch($p){
			case 1:
			$player->setNameTag("§c⚠§r".$name);
			$player->setDisplayName("§c⚠§r".$name);
			$player->save();
			break;
			case 2:
			$player->setNameTag("§c⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠§r".$name);
			$player->save();
			break;
			case 3:
			$player->setNameTag("§c⚠⚠⚠§r".$name);
			$player->setDisplayName("§c⚠⚠⚠§r".$name);
			$player->save();
			break;
		}
	}

	public function onEnable() :void{
		$this->getLogger()->notice("WarnSystemを読み込みました by smo");
		$this->getServer()->getPluginManager()->registerEvents($this, $this);
		if(!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0744, true);
						$this->c = new Config($this->getDataFolder() . "config.yml", Config::YAML);
	}

	/**
 * @priority MONITOR
 */
	public function onJoin(PlayerJoinEvent $event) :void{
		$player = $event->getPlayer();
		$name = $event->getPlayer()->getName();
		if(!$this->c->exists($name)) {
			$this->c->set($name, "N");
			$this->c->save();
		}else{
			switch($this->c->get($name)){
				case "N":
				break;
				case "1":
				$this->setWarnTag($player, 1);
				break;
				case "2":
				$this->setWarnTag($player, 2);
				break;
				case "3":
				$this->setWarnTag($player, 3);
				break;
			}
		}

		public function onCommand(CommandSender $sender, Command $command, String $label, array $args) :bool{
			switch($label){
				case "checkwarn":
				if(!$sender instanceof Player){
					$sender->sendMessage("§6>>§cゲーム内で実行してください");
				}else{
					switch($this->c->get($sender->getName())){
						case "N":
						$sender->sendMessage("§6>>§aあなたは警告されていません");
						break;
						case "1":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e1§cです");
						break;
						case "2":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e2§cです");
						break;
						case "3":
						$sender->sendMessage("§6>>§cあなたな累積警告は§e3§cです");
						break;
					}
				}
				break;
				case "warn":
				if(!isset($args[0])) return false;
				if(!issrt($args[1])) return false;
				switch($args[0]){
					case "add":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e3§aにしました");
						$this->c->set($args[1], "3");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§cの累積警告は既に最大値です");
					}
					break;
					case "remove":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§cは警告されていません");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を取り消しました");
						$this->c->set($args[1], "N");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e1§aにしました");
						$this->c->set($args[1], "1");
						$this->c->save();
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告を§e2§aにしました");
						$this->c->set($args[1], "2");
						$this->c->save();
					}
					break;
					case "check":
					if(!$this->c->exists($args[1])){
						$sender->sendMessage("§6>>§e".$args[1]."§cのデータがありません");
					}elseif($this->c->get($args[1]) === "N"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§eなし");
					}elseif($this->c->get($args[1]) === "1"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e1");
					}elseif($this->c->get($args[1]) === "2"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e2");
					}elseif($this->c->get($args[1]) === "3"){
						$sender->sendMessage("§6>>§e".$args[1]."§aの累積警告:§e3");
					}
					break;
				}
				break;
			}
			return true;
		}
}
}
anonymous No title
PHP
ああ
anonymous No title
PHP
function make_ary($x){
	$make_index_ary = function($x) use( &$make_index_ary ){
		if($x==1){
			return [1];
		}
		$first_list = array_map(function($x){
			return $x*2;
			},$make_index_ary($x-1));
		$latter_list = array_map(function($x){
			return $x-1;
			},array_reverse($first_list));
		return array_merge($first_list,$latter_list);
	};
	
	$index_ary = $make_index_ary($x);
	$edge_num = pow(2, $x-1);
	$ary = [];
	for($i=0;$i<$edge_num;$i++){
		$ary[$index_ary[$i]]=($i+1)*2;
	}
	ksort($ary);
	return $ary;
}

print_r (make_ary(5) );
//Array ( [1] => 22 [2] => 12 [3] => 28 [4] => 6 [5] => 20 [6] => 14 [7] => 30 [8] => 4 [9] => 24 [10] => 10 [11] => 26 [12] => 8 [13] => 18 [14] => 16 [15] => 32 [16] => 2 )
anonymous No title
PHP
function make_ary($x){
	if($x==1){
		return [2];	
	}
	$cur_list = make_ary($x-1);
	$x_last = end($cur_list);
	$add_list = array_map(function($x) use($x_last){
		return $x + $x_last;
	},$cur_list);
	$result = array_pad([0],count($cur_list)*2,0);
	
	$j = 0;
	foreach($result as $i => $int){
		if($i%2==0){
			$result[$i] = $cur_list[$j];
		}else{
			$result[$i] = $add_list[$j];
			$j++;
		}
	}
	return $result;
}

print_r( make_ary(5) );
// Array ( [0] => 2 [1] => 18 [2] => 10 [3] => 26 [4] => 6 [5] => 22 [6] => 14 [7] => 30 [8] => 4 [9] => 20 [10] => 12 [11] => 28 [12] => 8 [13] => 24 [14] => 16 [15] => 32 )
anonymous No title
Python
print(type(X_train_memmap))
print(len(X_train_memmap))
print(X_train_memmap.shape)
print(type(Y_train_memmap))
print(len(Y_train_memmap))
print(Y_train_memmap.shape)
print(type(X_test_memmap))
print(len(X_test_memmap))
print(X_test_memmap.shape)
print(type(Y_test_memmap))
print(len(Y_test_memmap))
print(Y_test_memmap.shape)

"""
<class 'numpy.memmap'>
637
(637, 360, 480, 3)
<class 'numpy.memmap'>
637
(637, 5)
<class 'numpy.memmap'>
215
(215, 360, 480, 3)
<class 'numpy.memmap'>
215
(215, 5)
"""

base_model = Xception(
	include_top=False,
	input_shape=(IMG_HEIGHT, IMG_WIDTH, 3),
	pooling='None'
)

# 全結合層の新規構築

top_model = Sequential()
top_model.add(GlobalAveragePooling2D())
top_model.add(Dense(1024, activation='relu'))
top_model.add(Dense(len(classes), activation='softmax'))

# 全結合層を削除したモデルと上で自前で構築した全結合層を結合
model = Model(inputs=base_model.input, outputs=top_model(base_model.output))

#全層 trainable
for layer in model.layers:
	layer.trainable = True

model.compile(optimizer=Adam(lr=0.001), loss='categorical_crossentropy', metrics=['accuracy'])

#過学習を起こさせるためにデータ水増しをしない
image_data_generator = ImageDataGenerator(
	featurewise_center = False,
	samplewise_center = False,
	featurewise_std_normalization = False,
	samplewise_std_normalization = False,
	zca_whitening = False,
	rotation_range = 0,
	width_shift_range = 0.0,
	height_shift_range = 0.0,
	horizontal_flip = False,
	vertical_flip = False
)

# reduce learning rate
reduce_lr = ReduceLROnPlateau(
	monitor = 'val_acc',
	factor = 0.5,
	patience = 5,
	verbose = 1
)

history = model.fit_generator(
	image_data_generator.flow(X_train_memmap, Y_train_memmap, batch_size=BATCH_SIZE),
	steps_per_epoch=(len(X_train_memmap) / BATCH_SIZE),
	epochs=EPOCH,
	validation_data=(X_test_memmap, Y_test_memmap),
	callbacks = [reduce_lr],
	initial_epoch=0
)
anonymous No title
C
#include <openssl/des.h>
#include <sys/time.h> // For time measures
#include <string.h>
#include <ctype.h>

// Encryption/Decryption switches
#define ENC 1
#define DEC 0

// From char to DES_LONG (be aware that c is shifted)
// char→DES型
#define c2l(c,l)    (l =((DES_LONG)(*((c)++))), \
                     l|=((DES_LONG)(*((c)++)))<< 8L, \
                     l|=((DES_LONG)(*((c)++)))<<16L, \
                     l|=((DES_LONG)(*((c)++)))<<24L)

// From DES_LONG to char (be aware that c is shifted)
// DES→char
#define l2c(l,c)	(*((c)++)=(unsigned char)(((l)     )&0xff), \
                     *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
                     *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
                     *((c)++)=(unsigned char)(((l)>>24L)&0xff))

void write_output(const char *filename, const unsigned char *in)
{
    // Now... Open the file binary with writing capabilities
    FILE *fp = fopen(filename, "wb");

    // If it can't be open, then return an error message
    if (fp == NULL) {fputs ("File error", stderr); exit (1);}

    // Write the in-array to specificed file-location
    fwrite(in, sizeof(unsigned char), strlen((const char *)in), fp);

    // Close the it
    fclose(fp);
}

const unsigned char *read_inputtext(const char *filename)
{
    // Total number of bytes
    unsigned long fsize;

    // Result of reading the file
    size_t result;

    // Now... Open the file binary with reading capabilities
    FILE *fp = fopen(filename, "rb");

    // If it can't be open, then return an error message
    if (fp == NULL) {fputs ("File error",stderr); exit (1);}

    /* Find out the number of bytes */
    fseek(fp, 0, SEEK_END);
    fsize = ftell(fp);      /* Get the size of the file */
    rewind(fp);             /* Go back to the start */

    // Allocate the buffer + 1 for termination
    unsigned char* buffer = malloc(fsize * sizeof *buffer + 1);

    // Test that everything went as we expected
    if(buffer == NULL) { fputs("Memory error!", stderr); exit(2); }

    // Read the buffer
    result = fread(buffer, 1, fsize * sizeof *buffer, fp);

    // Something went wrong when we read the file; sizes to not match
    if (result != fsize) {fputs ("Reading error", stderr); exit (3);}

    // Terminate the str
    buffer[fsize] = '\0';

    // Close the file
    fclose(fp);

    // Return the pointer to the dynamic allocated array
    return buffer;
}

void str2DES_cblock(const char *str, DES_cblock *out)
{
    // Make a char pointer and point it at the start of the array
    unsigned char *o;
    o = out[0];

    // Read the string
    int i;
    for (i = 0; i < 8; i++)
        sscanf(&(str[i*2]),"%2hhx", o++);
}

void my_des_cbc_encrypt(unsigned char *input, unsigned char *output, long length, DES_key_schedule ks, DES_cblock *ivec, int env){
  /*
    Assume that the input length (in byte) is a multiple of 8
    Try to undestand the macros l2c and c2l. They are important in implementation of CBC
    入力は8の倍数byte
  */

  unsigned char *iv;            // Initialization vector
  long l = length;

  DES_LONG xor0, xor1;
  DES_LONG in0, in1;
  DES_LONG data[2];
  /*
     Addtional variables
  */

  iv = ivec[0];

  //Initialize XOR-variables
  c2l(iv, xor0);
  c2l(iv, xor1);

  //Handling 8 bytes of input data each time inside the for loop.
  for(l = -8; l >= 0; l = -8){
    /*
      Your implementation of DES in CBC mode.
      Using des_encrypt1().
    */
    
  }
}

int main(int argc, char *argv[])
{
    int k;
    des_key_schedule key;
    DES_cblock iv, cbc_key;

    /*
      Other variables
    */
    const unsigned char *in;
    unsigned char *inp,*out;
    unsigned char *des_out;
    long s;
    FILE *fp; // ファイルポインタの作成
    char ch;
    char str[256];
    //DES_cblock in,out;
    /*
      Check number of command line arguments
    */
    if(argc != 5){
      printf("Not enough or too many arguments!\n");
      exit(1);
    }

    /*
      Check key and initialization vector validities. (comprise of Hexadicimal digits or not)
    */
    //16進数かを判定する関数
    if(isxdigit(*argv[1])!=1 || isxdigit(*argv[2])!=1) {
      if(isxdigit(*argv[1])!=1) printf("iv is not hexadecimal.\n");
      if(isxdigit(*argv[2])!=1) printf("key is not hexadecimal.\n");
      exit(2);
    }
    /*
      Convert key and initialization vector from string to DES_cblock
    */
    str2DES_cblock(argv[1],&iv);
    str2DES_cblock(argv[2],&cbc_key);
    //str2DES_cblock(argv[3],&in);
    //str2DES_cblock(argv[4],&out);
    /*
      read_inputtext();
    */
    fp = fopen(argv[3],"r");
    while(fgets(str, 256, fp) != NULL) {}
    fclose(fp);
    s = strlen(str) - 1;

    in = read_inputtext(argv[3]);
    inp = in;
    printf("%s",inp);

    /*
      my_des_cbc_encrypt();
    */

    //void my_des_cbc_encrypt(unsigned char *input, unsigned char *output, long length, DES_key_schedule ks, DES_cblock *ivec, int env){
    //my_des_cbc_encrypt(inp,out,s,key,&iv,ENC);
    //printf("%s\n", out);
    /*
      write_output();
    */
    //write_output(argv[4],x);

    //Compare the resutl with that using built-in funtion des_cbc_encrypt(). Details of des_cbc_encrypt() can be seen at http://web.mit.edu/macdev/Development/MITKerberos/MITKerberosLib/DESLib/Documentation/api.html
    /*
      des_cbc_encrypt();
    */
    des_cbc_encrypt(in,out,s,key,&iv,ENC);

    /*
     Print out ciphertexts from  my_des_cbc_encrypt() and  des_cbc_encrypt() to compare
    */
    printf("Plain text: ");
    fp = fopen(argv[3],"r");
    while( ( ch = fgetc(fp) ) != EOF ) {
      printf("%c", ch);
    }
    //printf("\n");
    fclose(fp);

    printf("Cipher text: ");
    fp = fopen(argv[4],"r");
    while( ( ch = fgetc(fp) ) != EOF ) {
      printf("%c", ch);
    }
    printf("\n");
    fclose(fp);

    return 0;
}
anonymous No title
Python
import random

while True:
    print('Choice your hand, input character.')
    print('Rock    : g')
    print('Paper   : p')
    print('Scissors: s')
    print('Exit    : e')

    user_input = input()

    if user_input == 'e':
        break
    else:
        ai_hand = random.randrange(3)

        if user_input == 'g':
            user_hand = 0
            print('User hand: Rock')
        elif user_input == 'p':
            user_hand = 1
            print('User hand: Paper')
        elif user_input == 's':
            user_hand = 2
            print('User hand: Scissors')
        else:
            print('Invalid input')
            continue

        if ai_hand == 0:
            print('AI hand  : Rock')
        elif ai_hand == 1:
            print('AI hand  : Paper')
        else:
            print('AI hand  : Scissors')

        if user_hand == (ai_hand + 1) % 3:
            print('Result   : Win')
        elif ai_hand == (user_hand + 1) % 3:
            print('Result   : Lose')
        else:
            print('Result   : Draw')

        print()