id
stringlengths
36
36
text
stringlengths
1
1.25M
43ccbff8-2092-4988-8a48-41a0b318f154
@GET @Path("/{id}") public Response getContact(@PathParam("id") int id, @Auth Boolean isAuthenticated) { // retrieve information about the contact with the provided id Contact contact = contactDao.getContactById(id); return Response .ok(contact) .build(); }
e488b5f5-d80e-4da8-9e64-be2fa755641d
@POST public Response createContact(Contact contact, @Auth Boolean isAuthenticated) throws URISyntaxException { // Validate the contact's data Set<ConstraintViolation<Contact>> violations = validator.validate(contact); // Are there any constraint violations? if (violations.size() > 0) { // Validation errors occurred ArrayList<String> validationMessages = new ArrayList<String>(); for (ConstraintViolation<Contact> violation : violations) { validationMessages.add(violation.getPropertyPath().toString() + ": " + violation.getMessage()); } return Response .status(Status.BAD_REQUEST) .entity(validationMessages) .build(); } else { // OK, no validation errors // Store the new contact int newContactId = contactDao.createContact(contact.getLocation()); return Response.created(new URI(String.valueOf(newContactId))).build(); } }
239b3939-38eb-4f44-8742-0570b45673ac
@DELETE @Path("/{id}") public Response deleteContact(@PathParam("id") int id, @Auth Boolean isAuthenticated) { // delete the contact with the provided id contactDao.deleteContact(id); return Response.noContent().build(); }
b2c8809d-69ff-49ec-aee8-129537f85d71
@PUT @Path("/{id}") public Response updateContact(@PathParam("id") int id, Contact contact, @Auth Boolean isAuthenticated) { // Validate the updated data Set<ConstraintViolation<Contact>> violations = validator.validate(contact); // Are there any constraint violations? if (violations.size() > 0) { // Validation errors occurred ArrayList<String> validationMessages = new ArrayList<String>(); for (ConstraintViolation<Contact> violation : violations) { validationMessages.add(violation.getPropertyPath().toString() + ": " + violation.getMessage()); } return Response .status(Status.BAD_REQUEST) .entity(validationMessages) .build(); } else { // No errors // update the contact with the provided ID contactDao.updateContact(id, contact.getLocation()); return Response.ok( new Contact(id, contact.getLocation())).build(); } }
2ee01c7b-9109-47ee-9c35-68a1366d35f9
public ContactView(Contact contact) { super("/views/contact.mustache"); this.contact = contact; }
82badecc-a6ea-458f-bb6e-37f08aa1fe1c
public Contact getContact() { return contact; }
32049a01-dd0f-4d89-a2bd-52790b4ae712
public Rabbit() { }
caa6a76d-e907-4e89-a164-e5d1d560bb9e
public Randomize(int x, int y) { }
9a624ea4-1887-4271-bb44-91a80cacaf68
public SnakeGame() { this.rabbitCount = 0; gameField = new GameField(); gameField.setVisible(true); gameField.setBackground(Color.WHITE); gameField.setLayout(null); this.add(gameField); this.setAutoRequestFocus(true); this.addKeyListener(this); this.setResizable(false); }
cf08799d-e358-4085-bf79-1283f26a54b9
@Override public void actionPerformed(ActionEvent e) { }
46d33c2d-c927-473f-93df-9a4271825fae
@Override public void keyTyped(KeyEvent e) { }
9163f437-b555-437d-9822-29815a04d5f8
@Override public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_UP) { Snake snake = gameField.getSnake(); Rabbit rabbit = gameField.getRabbit(); int snakeX = snake.getX(); int snakeY = snake.getY(); snake.setLocation(snakeX,snakeY-45); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } isBorder = gameField.isBorder(snake, e); if(isBorder) { snake.setLocation(snake.getX(), 616); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } } } if(e.getKeyCode() == KeyEvent.VK_DOWN) { Snake snake = gameField.getSnake(); Rabbit rabbit = gameField.getRabbit(); int snakeX = snake.getX(); int snakeY = snake.getY(); snake.setLocation(snakeX,snakeY+45); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } isBorder = gameField.isBorder(snake,e); if(isBorder) { snake.setLocation(snake.getX(),0); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } } } if(e.getKeyCode() == KeyEvent.VK_RIGHT) { Snake snake = gameField.getSnake(); Rabbit rabbit = gameField.getRabbit(); int snakeX = snake.getX(); int snakeY = snake.getY(); snake.setLocation(snakeX+45,snakeY); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } isBorder = gameField.isBorder(snake,e); if(isBorder) { snake.setLocation(0,snake.getY()); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } } } if(e.getKeyCode() == KeyEvent.VK_LEFT) { Snake snake = gameField.getSnake(); Rabbit rabbit = gameField.getRabbit(); int snakeX = snake.getX(); int snakeY = snake.getY(); snake.setLocation(snakeX-45,snakeY); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } isBorder = gameField.isBorder(snake,e); if(isBorder) { snake.setLocation(939,snake.getY()); isCrashed = gameField.isCrashed(snake,rabbit); if(isCrashed) { recreateRabbit(rabbit); } } } }
4597ebd7-34c7-4338-afe0-205f88302e4b
@Override public void keyReleased(KeyEvent e) { }
47e18dbd-45e4-4936-84e4-d8c1e479ead6
public void recreateRabbit(Rabbit rabbit) { gameField.remove(rabbit); gameField.createRabbit(); gameField.repaint(); this.rabbitCount++; this.setTitle("Rabbits: " + Integer.toString(this.rabbitCount)); }
b8c02f1d-e1c4-4f7d-9a48-beeeebbb6ec9
public GameField() { this.createSnake(); this.createRabbit(); }
3ef80d95-6d12-44d6-a8b5-0f14f4823255
public void createSnake() { snake = new Snake(); int x_AppearSnake = RandomX(); int y_AppearSnake = RandomY(); snake.setText("S"); snake.setSize(45,45 ); snake.setVisible(true); snake.setLocation(x_AppearSnake,y_AppearSnake); snake.setEnabled(false); this.add(snake); }
aa068647-c2ac-439d-9175-4c7c347675f7
public void createRabbit() { rabbit = new Rabbit(); int x_AppearRabbit = RandomX(); int y_AppearRabbit = RandomY(); rabbit.setSize(45,45); rabbit.setLocation(x_AppearRabbit, y_AppearRabbit); rabbit.setText("R"); rabbit.setEnabled(false); this.add(rabbit); rabbit.setVisible(true); }
73fd3d75-e233-48ca-98da-d2d2f6c8f7da
public int RandomX() { Random random = new Random(); return random.nextInt(1000-51); }
7aa5f7cb-6fd6-4bcd-aab0-6fd616c27e6e
public int RandomY() { Random random = new Random(); return random.nextInt(700-74); }
470cae08-4bb2-48d3-939f-c7a83bb825be
public Rabbit getRabbit() { return rabbit; }
afc498b3-3f36-4650-9ebe-4097baa1f038
public Snake getSnake() { return snake; }
e0a01a0f-fac3-4d92-85ee-fb477c2f84cf
public boolean isCrashed(Snake snake,Rabbit rabbit) { int sp1x,sp1y,sp2x,sp2y,sp3x,sp3y,sp4x,sp4y; int rp1x,rp1y,rp2x,rp2y,rp3x,rp3y,rp4x,rp4y; sp1x = snake.getX(); sp2x = snake.getX()+45; sp3x = snake.getX(); sp4x = snake.getX()+45; sp1y = snake.getY(); sp2y = snake.getY(); sp3y = snake.getY()+45; sp4y = snake.getY()+45; rp1x = rabbit.getX(); rp2x = rabbit.getX()+45; rp3x = rabbit.getX(); rp4x = rabbit.getX()+45; rp1y = rabbit.getY(); rp2y = rabbit.getY(); rp3y = rabbit.getY()+45; rp4y = rabbit.getY()+45; if((sp1x <= rp4x && sp1x >= rp3x) && (sp1y <= rp4y && sp1y >= rp2y)) return true; if(sp2x >= rp3x && sp2x <= rp4x && sp2y <= rp3y && sp2y >= rp1y) return true; if(sp3x <= rp2x && sp3x >= rp1x && sp3y >= rp2y && sp3y <= rp4y) return true; if(sp4x >= rp1x && sp4x <= rp2x && sp4y >= rp1y && sp4y <= rp3y) return true; return false; }
7f82abac-8811-4932-8f69-a4f6e920cfba
public boolean isBorder(Snake snake, KeyEvent keyEvent) { int sp2x = snake.getX()+60; int sp4y = snake.getY()+45; int sp1x = snake.getX(); if(sp2x >= 985 && keyEvent.getKeyCode() == KeyEvent.VK_RIGHT) return true; if(sp4y > 665 && keyEvent.getKeyCode() == KeyEvent.VK_DOWN) return true; if(sp4y <= 35&& keyEvent.getKeyCode() == KeyEvent.VK_UP) return true; if(sp1x < 0 && keyEvent.getKeyCode() == KeyEvent.VK_LEFT) return true; return false; }
57578add-2cda-41a1-9e96-19f03e1f3f8c
public static void main(String[] args) { SnakeGame snakeGame = new SnakeGame(); snakeGame.setVisible(true); snakeGame.setSize(1000,700); snakeGame.setTitle("Rabbits: 0"); snakeGame.setDefaultCloseOperation(snakeGame.EXIT_ON_CLOSE); }
710cb765-4d89-4883-a2ac-5a89a3e9cd83
public Snake() { }
1609f32e-fb1f-4779-ad8d-447cadc5fe93
@Test /* Very basic test to see if we can put in valid input and subsequently get that input back out. */ public void testGetValue() throws InvalidSuitException, InvalidFaceValueException { Card card = new Card('c', '3'); assertEquals(card.getValue(), "c3"); card = new Card("H4"); assertEquals(card.getValue(), "H4"); }
1a28c0a9-760d-499c-a2a7-b2511f230630
@Test /* Test the overridden equals operator. If two cards have the same suit and face value, they should * be considered equal. If not, they shouldn't. */ public void testEquals() throws InvalidSuitException, InvalidFaceValueException { Card card = new Card('c', '5'); assertTrue(card.equals(card)); Card sameCard = new Card('c', '5'); assertTrue(card.equals(sameCard)); Card differentCard = new Card('c', '6'); assertFalse(card.equals(differentCard)); }
b60dec45-b617-4d5e-928b-a2af29d40d55
@Test /* Very basic test to see if we can put in valid input and subsequently get that input back out. */ public void testGetSuit() throws InvalidSuitException { Suit suit = new Suit('H'); assertEquals('H', suit.getSuit()); }
fd69333f-82a4-4b8c-b0d8-23b612a688a8
@Test(expected = com.mergermarket.exception.InvalidSuitException.class) /* Test that bad input to the constructor results in an exception. */ public void testInvalidConstructorInput() throws InvalidSuitException { Suit suit = new Suit('X'); }
b8fab1d9-aebb-4db7-9165-6927bd34eabc
@Test /* Test that isValid does the right thing with both valid and invalid input. */ public void testIsValid() { Suit suit = new Suit(); // Test with valid input assertEquals(true, suit.isValid('D')); // Test with invalid input assertEquals(false, suit.isValid('S')); }
be6740e9-86ef-42b8-9937-68ec532c9d09
@Test /* Test that getValidInputs returns the expected list of chars. */ public void testGetValidInputs() { char[] expectedValidInputs = { 'D', 'H', 'c', 's' }; assertArrayEquals(expectedValidInputs, Suit.getValidInputs()); }
460e501e-53f2-406d-8e36-ec02a0fa14fd
@Test /* Very basic test to see if we can put in valid input and subsequently get that input back out. */ public void testGetFaceValue() throws InvalidFaceValueException { // Test with a letter FaceValue faceValue = new FaceValue('T'); assertEquals('T', faceValue.getFaceValue()); // Now test with a number faceValue = new FaceValue('2'); assertEquals('2', faceValue.getFaceValue()); }
3a2db962-8918-4681-88af-7ac022ac2d4a
@Test(expected = com.mergermarket.exception.InvalidFaceValueException.class) /* Test that bad input to the constructor results in an exception. */ public void testInvalidConstructorInput() throws InvalidFaceValueException { FaceValue faceValue = new FaceValue('B'); }
5825a32b-6a81-496c-b0a5-412fda62492c
@Test /* Test that isValid does the right thing with both valid and invalid input. */ public void testIsValid() { FaceValue faceValue = new FaceValue(); // Test with valid input assertEquals(true, faceValue.isValid('3')); // Test with invalid input assertEquals(false, faceValue.isValid('S')); }
1bd3d448-7cc8-42b8-811c-5fde23e24f1b
@Test /* Test that getValidInputs returns the expected list of chars. */ public void testGetValidInputs() { char[] expectedValidInputs = { 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K' }; assertArrayEquals(expectedValidInputs, FaceValue.getValidInputs()); }
6abd8a60-968f-445a-a443-28a87171a208
@Test /* Very basic test to see that we can create and then access the required number of cards. */ public void testGetCards() throws InvalidSuitException, InvalidFaceValueException { int numValidSuits = Suit.getValidInputs().length; int numValidFaceValues = FaceValue.getValidInputs().length; Deck deck = new Deck(); List<Card> cards = deck.getCards(); assertEquals(numValidSuits * numValidFaceValues, cards.size()); }
45ae186e-6e4d-4230-ae3e-be1a606a1fbe
@Test /* Test that shuffle changes the order of the cards. */ public void testShuffle() throws InvalidSuitException, InvalidFaceValueException { Deck deck = new Deck(); // Make a copy of the cards before shuffling. List<Card> unshuffled = new ArrayList<>(); for (Card c : deck.getCards()) { unshuffled.add(c); } // Now shuffle. deck.shuffle(); List<Card> shuffled = deck.getCards(); // Look for a card, any card, that's not in the same place in the array that it used to be. for (int i = 0; i < unshuffled.size(); i++) { Card before = unshuffled.get(i); Card after = shuffled.get(i); if (!(before.equals(after))) { return; } } // If we've gone all the way through the deck and the cards are all the same, fail. // (It may be theoretically possible that shuffling the deck could result in no changes to // the card ordering, but I think that possibility is remote enough that we can discount // it here.) fail("Order of cards did not change after shuffle"); }
09f2e0a3-8692-45b1-9bd4-798d22f9f488
@BeforeClass /** Set up the deck of cards and, for convenience, put all the cards into a Set that * we can then use as a lookup table for checking if a card is a 'real' card. */ public static void setUp() throws InvalidSuitException, InvalidFaceValueException { deck = new Deck(); cardValuesInDeck = new HashSet<>(); for (Card c : deck.getCards()) { cardValuesInDeck.add(c.getValue()); } }
f3531eab-9fc3-4afe-b534-3365bc89d33e
@Before public void before() throws InvalidGameStateException { layout = new Layout(deck); }
ba288c33-fd54-4050-be22-ece5f2c504f5
@Test /** Test that the constructor sets up the initial state of the game correctly. * This is a bit tricky because of: * - the randomness element of shuffling the cards * - the fact that the class's contract with the outside world is just via * text output (we could use reflection to examine the class's internal state, * but I'm not a big fan of that as we're then testing what the code is rather * than what the code does -- which in my experience makes the tests hard to * maintain) */ public void testInitialLayout() throws InvalidGameStateException { List<String> initialState = layout.print(); assertEquals(9, initialState.size()); assertTrue(initialState.get(0). contains("ColumnNames S[T]ack [1] [2] [3] [4] [5] [6] [7] [D] [H] [c] [s]")); // I'm not going to make assertions about the row of dashes as I don't think it's important // and I don't want to make this test brittler than it already is. // The first row of cards should contain six (and not seven) face down cards. assertTrue(initialState.get(2).contains("** ** ** ** ** **")); assertFalse(initialState.get(2).contains("** ** ** ** ** ** **")); // The first card in the first row should be a valid card. String firstCardFirstRow = initialState.get(2).substring(29,31); assertTrue(cardValuesInDeck.contains(firstCardFirstRow)); // The second row of cards should contain five (and not six) face down cards. assertTrue(initialState.get(3).contains("** ** ** ** **")); assertFalse(initialState.get(3).contains("** ** ** ** ** **")); // The first card in the second row should be a valid card. String firstCardSecondRow = initialState.get(3).substring(33,35); assertTrue(cardValuesInDeck.contains(firstCardSecondRow)); // The last row of cards should contain no face down cards. assertFalse(initialState.get(8).contains("**")); // The first card in the last row should be a valid card. String firstCardLastRow = initialState.get(8).substring(53,55); assertTrue(cardValuesInDeck.contains(firstCardLastRow)); }
ce71376f-1366-4c8a-ba60-b164bbe1ceca
@Test(expected = com.mergermarket.exception.InvalidGameStateException.class) /** Test that the game won't start if the deck doesn't meet the requirements for this game. */ public void testWrongNumberOfCardsInDeck() throws InvalidFaceValueException, InvalidSuitException, InvalidGameStateException { // Set up a mock deck with only 1 card in it. Card card = new Card('c', 'A'); List<Card> badCards = new ArrayList<>(); badCards.add(card); Deck badDeck = mock(Deck.class); when(badDeck.getCards()).thenReturn(badCards); Layout layout = new Layout(badDeck); }
00675cae-14be-4266-ab85-8afb3d3984d5
@Test /** Test that processMove returns false if the given move is not allowed (not to be confused * with invalid due to the state of the game). */ public void testProcessMoveWithDisallowedInput() throws InvalidGameStateException, InvalidFaceValueException, InvalidSuitException { assertFalse(layout.processMove("")); assertFalse(layout.processMove("F")); assertFalse(layout.processMove("SomeTooLongString")); assertFalse(layout.processMove("c2 X")); assertFalse(layout.processMove("X2 c")); assertFalse(layout.processMove("c2 0")); assertFalse(layout.processMove("c2 8")); assertFalse(layout.processMove("c2 10")); }
0ef37116-a0d6-490c-a938-7c8dbe5a7b24
@Test /** Test that starting a new game causes the cards to be re-shuffled. */ public void testStartingNewGame() throws InvalidGameStateException, InvalidFaceValueException, InvalidSuitException { List<String> firstState = layout.print(); assertTrue(layout.processMove("N")); List<String> secondState = layout.print(); for (int i = 0; i < firstState.size(); i++) { if (!(firstState.get(i).equals(secondState.get(i)))) { return; } } fail("Game state didn't change when new game started"); }
d11e067b-2bf8-43c7-a0f7-0d819932aa8c
@Test /** Test turning over cards with the draw stack in various states. */ public void testTurningDrawStack() throws InvalidFaceValueException, InvalidSuitException, InvalidGameStateException { Layout layout = createUnshuffledLayout(); // Test basic card turning, hitting the end of the draw stack, plus // going back to the beginning when we hit the end. String[] values = {"D6", "D9", "DQ", "H2", "H5", "H8", "HJ", "D3"}; for (String s : values) { assertEquals(true, layout.processMove("T")); List<String> state = layout.print(); assertEquals(s, getTopDrawStackCard(state)); } }
af23e54d-3662-4253-93d2-14fca22dba61
@Test /** Test moving cards in various ways: * - from draw stack to a column * - from draw stack to a discard pile * - from column to another column * - from column to discard pile */ public void testMoveCard() throws InvalidFaceValueException, InvalidSuitException, InvalidGameStateException { Layout layout = createUnshuffledLayout(); // NB: This test generates invalid moves, which is fine for now, but // the test will need refactoring when and if we add move validity checking. // Move 3 cards (sequentially) from the top of the draw stack to column 1. Check that they // stack correctly and that the draw stack continues to display correctly (including // turning over 3 more cards automatically when the stack becomes empty). assertTrue(layout.processMove("D3 1")); List<String> state = layout.print(); assertTrue(state.get(2).contains(" D2 ")); assertTrue(state.get(3).contains("D3 sJ ** ** ** ** **")); assertTrue(layout.processMove("D2 1")); state = layout.print(); assertTrue(state.get(2).contains(" DA ")); assertTrue(state.get(3).contains("D3 sJ ** ** ** ** **")); assertTrue(state.get(4).contains("D2 s8 ** ** ** **")); assertTrue(layout.processMove("DA 1")); state = layout.print(); assertTrue(state.get(2).contains(" D6 ")); assertTrue(state.get(3).contains("D3 sJ ** ** ** ** **")); assertTrue(state.get(4).contains("D2 s8 ** ** ** **")); assertTrue(state.get(5).contains("DA s4 ** ** **")); // Move a card from the top of the draw stack to a discard pile. assertTrue(layout.processMove("D6 H")); state = layout.print(); assertTrue(state.get(2).contains("sK ** ** ** ** ** ** D6")); // Move 2 cards (sequentially) from a column to a discard pile. assertTrue(layout.processMove("DA D")); state = layout.print(); assertTrue(state.get(2).contains("sK ** ** ** ** ** ** DA D6")); assertFalse(state.get(5).contains("DA")); assertTrue(layout.processMove("D2 D")); state = layout.print(); assertTrue(state.get(2).contains("sK ** ** ** ** ** ** D2 D6")); // Move all the cards from one column to another, resulting in an empty column. assertTrue(layout.processMove("sK 2")); state = layout.print(); assertTrue(state.get(2).contains(" ** ** ** ** ** ** D2 D6")); assertTrue(state.get(4).contains(" sK s8 ** ** ** **")); assertTrue(state.get(5).contains(" D3 s4 ** ** **")); // Move all the face-up cards from one column to another. Make sure the // last card in the source column gets turned face up. assertTrue(layout.processMove("sJ 3")); state = layout.print(); assertTrue(state.get(2).contains(" sQ ** ** ** ** **")); // Move some of the face-up cards from one column to another. assertTrue(layout.processMove("sJ 7")); state = layout.print(); assertTrue(state.get(4).contains("s8 ** ** ** **")); assertTrue(state.get(8).contains("HQ")); assertTrue(state.get(9).contains("sJ")); assertTrue(state.get(10).contains("sK")); assertTrue(state.get(11).contains("D3")); // Try to move a column of cards to a discard pile. The move should // come back as unprocessed. assertFalse(layout.processMove("HQ c")); // Try to move a card that's not face up. The move should come back // as unprocessed. assertFalse(layout.processMove("c9 1")); }
e958f5c9-1e64-44f9-9227-144fbf727352
private String getTopDrawStackCard(final List<String> state) { return state.get(2).substring(19,21); }
bee126c3-269a-49e5-84be-3021fc59b652
private Layout createUnshuffledLayout() throws InvalidFaceValueException, InvalidSuitException, InvalidGameStateException { Deck deck = createUnshufflableDeck(); return new Layout(deck); }
89710582-dd7c-472a-ac7f-d7cd383e0afb
private Deck createUnshufflableDeck() throws InvalidFaceValueException, InvalidSuitException { List<Card> cards = new ArrayList<>(); char[] suits = { 'D', 'H', 'c', 's' }; char[] faceValues = { 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K' }; for (char suit : suits) { for (char faceValue : faceValues) { cards.add(new Card(suit, faceValue)); } } Deck deck = mock(Deck.class); when(deck.getCards()).thenReturn(cards); Mockito.doNothing().when(deck).shuffle(); return deck; }
bb2f6b69-dd07-4565-a717-ce02f2dd3a3a
public static void main(String[] args) { // write your code here }
5d772817-c5a9-4a06-97f6-fce2e60230a6
public Card() { }
2b18529c-5541-435b-93e2-65ad40e0738c
public Card(final char suit, final char faceValue) throws InvalidSuitException, InvalidFaceValueException { this.suit = new Suit(suit); this.faceValue = new FaceValue(faceValue); this.faceUp = false; }
9f725284-dec5-4f56-b6be-c2d086d074b6
public Card(final String cardValue) throws InvalidSuitException, InvalidFaceValueException { char suit = cardValue.charAt(0); char faceValue = cardValue.charAt(1); this.suit = new Suit(suit); this.faceValue = new FaceValue(faceValue); this.faceUp = false; }
df87d760-fe79-4c6a-a5d2-b69beedfb33d
public String getValue() { return String.valueOf(suit.getSuit()) + String.valueOf(faceValue.getFaceValue()); }
a585792d-6e46-4f58-a96e-a335208baf53
@Override /** * Useful shorthand for determining if one Card is the same as another. Two cards * are considered the same if they have the same value (suit + face value). * @return true if the cards are the same, false if not. */ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Card card = (Card) o; if (this.getValue().equals(card.getValue())) { return true; } else { return false; } }
a7ae5233-ebbf-4ac6-aa83-b8b73a8e7b3d
public boolean isFaceUp() { return faceUp; }
e10b9753-4165-42c1-9b98-6ae419147861
public void setFaceUp(boolean faceUp) { this.faceUp = faceUp; }
e7a88fc1-31d5-4290-a9db-4a67adba1b9e
public FaceValue() { }
ba665048-7fd0-4d8e-9055-d13a91c1a7ef
public FaceValue(final char input) throws InvalidFaceValueException { if (isValid(input)) { setFaceValue(input); } else { throw new InvalidFaceValueException("Invalid face value " + input + " passed to FaceValue constructor"); } }
b549e3c9-e823-4080-b928-1d021875536f
public boolean isValid(final char input) { return isValid(input, validInputs); }
ef841bfc-7b7a-47b0-9b1e-3c6e52684148
public static char[] getValidInputs() { return validInputs; }
ecd83bc3-6f98-4ddc-a7df-f60c388e8105
public char getFaceValue() { return faceValue; }
487d7758-8abc-4fc1-9e90-1ba67299f7eb
public void setFaceValue(final char faceValue) { this.faceValue = faceValue; }
7fbec9cf-1f53-4ca0-9e4a-0bd12c9ceb51
public Suit() { }
9c3cb842-90a8-4a0d-b499-2fa1cede4d72
public Suit(final char input) throws InvalidSuitException { if (isValid(input)) { setSuit(input); } else { throw new InvalidSuitException("Invalid suit " + input + " passed to Suit constructor"); } }
bb668ddc-a4bb-4f6c-aea2-05971f2d9301
public boolean isValid(final char input) { return isValid(input, validInputs); }
f713b711-f5e4-4e6a-a412-be63dd69f190
public static char[] getValidInputs() { return validInputs; }
f98d5728-ff22-44a2-8cd8-f2d11a365547
public char getSuit() { return suit; }
775a6fe6-96e3-4604-b323-86f8b421c540
public void setSuit(final char suit) { this.suit = suit; }
792b21d5-3c4a-4451-972a-3f07a50d0da1
public boolean isValid(final char input, final char[] validInputs) { /* We could implement binary search here instead of just linearly iterating through the array, but because we expect the number of items in the array to be relatively small, any performance boost would be minimal. Another option would be to use a HashMap which we populate at object creation time. */ for (char t : validInputs) { if (t == input) { return true; } } return false; }
7923a80a-e2df-4610-a1ad-6b85606639d9
public Deck() throws InvalidSuitException, InvalidFaceValueException { cards = new ArrayList<Card>(); for (char suit : Suit.getValidInputs()) { for (char faceValue : FaceValue.getValidInputs()) { cards.add(new Card(suit, faceValue)); } } }
c1ea768b-f045-4c1f-a900-c9e467b18941
public void shuffle() { Collections.shuffle(cards); }
8abab053-5313-4b86-b2a8-6286a50f59f8
public List<Card> getCards() { return cards; }
28274d0d-ebab-4565-9d60-6ef4478c11c8
public Layout(Deck deck) throws InvalidGameStateException { this.deck = deck; initialise(); }
3467ae0b-379f-4ec5-bf15-b6a3a5d01c5c
public void initialise() throws InvalidGameStateException { // Put everything in the draw stack to begin with. deck.shuffle(); drawStack = new ArrayList<>(); for (Card c : deck.getCards()) { drawStack.add(c); } // Make sure that the deck has the right number of cards for this game. int numCards = drawStack.size(); if (numCards != 52) { throw new InvalidGameStateException("Can't start game with " + numCards + " cards, need 52"); } // Then move cards from the draw stack into the initial configuration // of the columns. columns = new ArrayList<>(); for (int i = 0; i < NUM_COLUMNS; i++) { List<Card> column = new ArrayList<>(); for (int j = 0; j <= i; j++) { Card c = drawStack.remove(drawStack.size() - 1); if (i==j) { c.setFaceUp(true); } else { c.setFaceUp(false); } column.add(c); } columns.add(column); } // Set up empty discard piles and fresh draw stack. discardPiles = new HashMap<>(); topDrawStackIndex = NUM_CARDS_TO_TURN - 1; }
845f0c8c-9112-431a-88f8-1a19836c3f21
public boolean processMove(final String move) throws InvalidGameStateException, InvalidFaceValueException, InvalidSuitException { if (!isAllowedMove(move)) { return false; } if (move.equals(NEW_GAME)) { initialise(); return true; } if (move.equals(TURN)) { turnDrawStack(); return true; } // If we're here, it's a move card to column move. Card card = new Card(move.substring(0, 2)); String column = move.substring(3); return moveColumn(card, column); }
d9f37d6b-8d55-40d5-b0e9-cd1425defe2f
private boolean moveColumn(final Card card, final String where) { // Figure out if the destination is a numbered column or a discard pile. boolean goingToDiscardPile = false; int column = 0; String suit = ""; try { column = Integer.parseInt(where); } catch (NumberFormatException e) { suit = where; goingToDiscardPile = true; } // If the card is the top card in the draw stack, remove it from the draw // stack and put it in the destination. Card topDrawStack = drawStack.get(topDrawStackIndex); if (topDrawStack.equals(card)) { card.setFaceUp(true); drawStack.remove(card); // Reveal the previous card in the draw stack. If there is no // previous card to reveal, do a turn-cards move automatically. topDrawStackIndex -= 1; if (topDrawStackIndex < 0) { turnDrawStack(); } if (goingToDiscardPile) { discardPiles.put(suit, card); } else { columns.get(column - 1).add(card); } return true; } // The card isn't the top card in the draw stack, so it must be in // one of the numbered columns. for (List<Card> columnToSearch : columns) { for (Card cardToCompare : columnToSearch) { if (cardToCompare.isFaceUp() && cardToCompare.equals(card)) { // Found it, now move it and everything below it. int lastCardIndex = columnToSearch.size() - 1; int indexFoundAt = columnToSearch.indexOf(cardToCompare); if (goingToDiscardPile) { // It doesn't make sense to move multiple cards from a column into the // same discard pile, so don't do it. if (lastCardIndex > indexFoundAt) { return false; } else { columnToSearch.remove(cardToCompare); discardPiles.put(suit, cardToCompare); return true; } } for (int i = indexFoundAt; i <= lastCardIndex; i++) { columns.get(column - 1).add(columnToSearch.get(indexFoundAt)); columnToSearch.remove(indexFoundAt); } // If there are any cards left in the source column, flip the last one face up. int newColumnSize = columnToSearch.size(); if (newColumnSize > 0) { columnToSearch.get(newColumnSize - 1).setFaceUp(true); } return true; } } } // If we're here, we haven't found the card we're supposed to move. return false; }
f1818417-7ca1-4faa-9954-c840cfb09f4a
private void turnDrawStack() { int size = drawStack.size(); int lastIndex = size - 1; // Check that there's something in the draw stack to turn. if (size == 0) { return; } // If we're at the very end of the stack, go back to the beginning // and proceed to turn over a batch of cards. (The requirement around // this is a bit vague. I'm interpreting "refresh the Stack from the // Waste pile" to mean go back to the beginning of the stack and then // turn over cards.) if (topDrawStackIndex == lastIndex) { topDrawStackIndex = -1; } // Can we turn over a batch of cards without running off the end? if (size > topDrawStackIndex + NUM_CARDS_TO_TURN) { topDrawStackIndex += NUM_CARDS_TO_TURN; } else { topDrawStackIndex = lastIndex; } }
3f656784-213c-4c51-be01-c8d82784f813
private boolean isAllowedMove(final String move) { return (move.equals(NEW_GAME) || move.equals(TURN) || isAllowedColumnMove(move)); }
ee6f71b4-dd9f-4d60-815c-b70c7bea8200
private boolean isAllowedColumnMove(final String move) { // We expect a two-character card value, a space, then a column number. String cardValue, column; try { cardValue = move.substring(0, 2); column = move.substring(3); } catch (StringIndexOutOfBoundsException e) { return false; } // Let the Card constructor tell us whether we've got a valid card. try { Card card = new Card(cardValue); } catch (InvalidSuitException | InvalidFaceValueException | StringIndexOutOfBoundsException e) { return false; } // Ask the Suit constructor whether the column we have is a discard pile. if (column.length() == 1) { try { Suit columnAsSuit = new Suit(column.charAt(0)); return true; } catch (InvalidSuitException e) { } } // Ask the Integer constructor whether the column we have is a number, // then ask this class's internal state whether that column is valid. try { Integer columnAsInt = new Integer(column); return (columnAsInt >= 1 && columnAsInt <= columns.size()); } catch (NumberFormatException e) { return false; } }
fdaf92d1-498a-49d8-a632-4fdd3f8e2ef7
public List<String> print() { String header = "ColumnNames S[T]ack "; for (int i = 1; i <= NUM_COLUMNS; i++) { header += "[" + i + "] "; } for (char s : Suit.getValidInputs()) { header += "[" + s + "] "; } String separator = ""; for (int i = 0; i < header.length(); i++) { separator += "-"; } // If there are any cards in the draw stack, get the top one. Otherwise display blanks. // (The draw stack will be empty if all the cards are in the discard piles, i.e. if the game // is won.) String topDrawStackValue = drawStack.size() > 0 ? drawStack.get(topDrawStackIndex).getValue() : BLANK_CARD; // The first line of actual card data contains the draw stack and the discard piles. String firstRow = FIRST_ROW_BUFFER + topDrawStackValue + FIRST_ROW_DRAW_STACK_BUFFER; firstRow += getColumnsSlice(0); for (char s : Suit.getValidInputs()) { firstRow += " "; if (discardPiles.containsKey(String.valueOf(s))) { firstRow += discardPiles.get(String.valueOf(s)).getValue(); } else { firstRow += BLANK_CARD; } } // Subsequent lines of card data don't need to worry about the draw stack or discard piles. List<String> moreRows = new ArrayList<>(); int longestColumn = longestColumnLength(); for (int i = 1; i < longestColumn; i++) { String thisRow = LATER_ROW_BUFFER; thisRow += getColumnsSlice(i); moreRows.add(thisRow); } List<String> output = new ArrayList<>(); output.add(header); output.add(separator); output.add(firstRow); for (String row : moreRows) { output.add(row); } return output; }
cd377d00-96cd-4b88-aaa6-6d6a1682a797
private String getColumnsSlice(final int index) { String result = ""; for (int i = 0; i < NUM_COLUMNS; i++) { List<Card> column = columns.get(i); if (column.size() > index) { Card c = column.get(index); result += c.isFaceUp() ? c.getValue() : FACE_DOWN; } else { result += BLANK_CARD; } result += SPACE_BETWEEN_COLUMNS; } return result; }
2e6baace-7db6-4d2b-b0d0-df09fe02edc0
private int longestColumnLength() { int max = 0; for (List<Card> column : columns) { int thisSize = column.size(); if (thisSize > max) { max = thisSize; } } return max; }
eba4c39f-c6d5-4e31-8297-e3c1a90cc0f2
public InvalidFaceValueException(final String message) { super(message); }
1569d82d-3f87-4530-9955-6ab38a484e46
public InvalidSuitException(final String message) { super(message); }
c376d2e0-ca19-4532-ad80-cd1c9f8513bd
public InvalidGameStateException(final String message) { super(message); }
ea6cb03d-bc76-45c6-a999-926d7283a4d5
public static void main(String[] args) { GraphicalUserInterface GUI = new GraphicalUserInterface(); GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GUI.setSize((System.getProperty("os.name").contains("Windows"))?(WIDTH + 4):WIDTH, (System.getProperty("os.name").contains("Windows"))?(HEIGHT + 5):HEIGHT); GUI.setIconImage(Toolkit.getDefaultToolkit().getImage(GUI.getClass().getResource("images/Application_Icon.png"))); GUI.setResizable(false); GUI.setVisible(true); }
9c8b3dd3-82bf-407a-881d-d898714d0687
public GraphicalUserInterface() { super("Liuizer (" + Resources.VERSION_NUMBER + " - " + Resources.VERSION_CODENAME + ") - The All-In-One ECE 489 Solver"); FlowLayout fl = new FlowLayout(); fl.setAlignment(FlowLayout.LEFT); setLayout(fl); createPanes(); setupTabs(); }
c4a1b5e8-ff74-4daf-9a78-90ba05357a85
private void createPanes() { createCaesarPane(); createDESPane(); createRSAPane(); }
2a73a0d3-dedd-4c5f-b201-386476e46d42
private void createCaesarPane() { // Input Panel caesarInputPanel.add(new JLabel(Resources.ccInputString + ":")); JTextField jTFInput = new JTextField(); jTFInput.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); caesarInputPanel.add(jTFInput); JLabel jL = new JLabel(Resources.ccSpinnerString + ":"); jL.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); caesarInputPanel.add(jL); caesarAddSpinners.setPreferredSize(new Dimension(45, 25)); caesarRemoveSpinners.setPreferredSize(new Dimension(45, 25)); caesarInputPanel.add(caesarAddSpinners); caesarInputPanel.add(caesarRemoveSpinners); caesarInputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 115)); // Spinner Panel JSpinner jSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 26, 1)); jSpinner.setPreferredSize(new Dimension(50, 25)); caesarSpinnerPanel.add(jSpinner); caesarSpinnerPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 30)); // Button Panel JLabel space = new JLabel(" "); space.setPreferredSize(new Dimension(jTP_WIDTH-200, 25)); caesarButtonPanel.add(space); caesarButtonPanel.add(caesarReverse); caesarShiftButton.setPreferredSize(new Dimension(100, 25)); caesarButtonPanel.add(caesarShiftButton); caesarButtonPanel.setPreferredSize(new Dimension(jTP_WIDTH-15, 60)); // Output Panel caesarOutputPanel.add(new JLabel(Resources.ccOutputString + ":")); JTextField jTFOutput = new JTextField(); jTFOutput.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); caesarOutputPanel.add(jTFOutput); caesarOutputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 100)); pane_caesar.add(caesarInputPanel); pane_caesar.add(caesarSpinnerPanel); pane_caesar.add(caesarButtonPanel); pane_caesar.add(caesarOutputPanel); caesarAddSpinners.addActionListener(this); caesarRemoveSpinners.addActionListener(this); caesarShiftButton.addActionListener(this); }
e30f41cc-1344-4896-86af-593b3d57d3d7
private void createDESPane() { // Input Panel desInputPanel.add(new JLabel(Resources.desInputString + ":")); JTextField jTFInput = new JTextField(); jTFInput.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); desInputPanel.add(jTFInput); desInputPanel.add(new JLabel(Resources.desKeyString + ":")); JTextField jTFKey = new JTextField(); jTFKey.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); desInputPanel.add(jTFKey); desInputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 110)); // Button Panel desEncryptButton.setPreferredSize(new Dimension(100, 25)); desButtonPanel.add(desEncryptButton); desButtonPanel.setPreferredSize(new Dimension(jTP_WIDTH-15, 30)); // Output Panel desOutputPanel.add(new JLabel(Resources.desOutputString + ":")); desOutputPane.setPreferredSize(new Dimension(jTP_WIDTH-23, 352)); ((JTextArea)((JViewport)desOutputPane.getComponent(0)).getView()).setEditable(false); desOutputPanel.add(desOutputPane); desOutputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 500)); pane_DES.add(desInputPanel); pane_DES.add(desButtonPanel); pane_DES.add(desOutputPanel); rsaEncryptButton.addActionListener(this); }
fd3d9023-ad4b-4c6e-8f24-09707ab6b4ab
private void createRSAPane() { // Input Panel rsaInputPanel.add(new JLabel(Resources.rsaInputP + ":")); JTextField jTFInputP = new JTextField(); jTFInputP.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); rsaInputPanel.add(jTFInputP); rsaInputPanel.add(new JLabel(Resources.rsaInputQ + ":")); JTextField jTFInputQ = new JTextField(); jTFInputQ.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); rsaInputPanel.add(jTFInputQ); rsaInputPanel.add(new JLabel(Resources.rsaInputE + ":")); JTextField jTFInputE = new JTextField(); jTFInputE.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); rsaInputPanel.add(jTFInputE); rsaInputPanel.add(new JLabel(Resources.rsaInputM + ":")); JTextField jTFInputM = new JTextField(); jTFInputM.setPreferredSize(new Dimension(jTP_WIDTH-24, 25)); rsaInputPanel.add(jTFInputM); rsaInputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 210)); // Button Panel rsaEncryptButton.setPreferredSize(new Dimension(160, 25)); rsaButtonPanel.add(rsaEncryptButton); rsaButtonPanel.setPreferredSize(new Dimension(jTP_WIDTH-15, 30)); // Output Panel rsaOutputPanel.add(new JLabel(Resources.rsaOutputString + ":")); rsaOutputPane.setPreferredSize(new Dimension(jTP_WIDTH-23, 252)); ((JTextArea)((JViewport)rsaOutputPane.getComponent(0)).getView()).setEditable(false); rsaOutputPanel.add(rsaOutputPane); rsaOutputPanel.setPreferredSize(new Dimension(jTP_WIDTH-10, 300)); pane_RSA.add(rsaInputPanel); pane_RSA.add(rsaButtonPanel); pane_RSA.add(rsaOutputPanel); desEncryptButton.addActionListener(this); }
dbbf67f2-98e4-4f01-8d07-25efb5785d4c
private void setupTabs() { jTP.setPreferredSize(new Dimension(jTP_WIDTH, jTP_HEIGHT)); jTP.addTab("Caesar Cipher", pane_caesar); jTP.addTab("DES Encryption", pane_DES); jTP.addTab("RSA Encryption", pane_RSA); add(jTP); }
f831d292-609e-41a3-a79d-bca26d88a4e1
@Override public void actionPerformed(ActionEvent e) { if(e.getSource() == caesarShiftButton) { String inputString = ((JTextField)caesarInputPanel.getComponent(1)).getText(); int[] charSteps = new int[caesarSpinnerPanel.getComponentCount()]; for(int i = 0; i < charSteps.length; i++) charSteps[i] = (int)((JSpinner)caesarSpinnerPanel.getComponent(i)).getValue(); boolean right = (caesarReverse.isSelected())?false:true; String outputString = Caesar.shift(inputString, charSteps, right); ((JTextField)caesarOutputPanel.getComponent(1)).setText(outputString); } else if(e.getSource() == caesarAddSpinners) { if(caesarSpinnerPanel.getComponentCount() < 13) { JSpinner jSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 26, 1)); jSpinner.setPreferredSize(new Dimension(50, 25)); caesarSpinnerPanel.add(jSpinner); revalidate(); repaint(); } } else if(e.getSource() == caesarRemoveSpinners) { if(caesarSpinnerPanel.getComponentCount() > 1) { caesarSpinnerPanel.remove(caesarSpinnerPanel.getComponentCount() - 1); revalidate(); repaint(); } } else if(e.getSource() == desEncryptButton) { String message = ((JTextField)desInputPanel.getComponent(1)).getText(); String key = ((JTextField)desInputPanel.getComponent(3)).getText(); ArrayList<String> output = DES.encrypt(key, message); String outputString = ""; for(int i = 0; i < output.size(); i++) outputString += output.get(i); // Set Output ((JTextArea)((JViewport)desOutputPane.getComponent(0)).getView()).setText(outputString); } else if(e.getSource() == rsaEncryptButton) { String pIn = ((JTextField)rsaInputPanel.getComponent(1)).getText(); String qIn = ((JTextField)rsaInputPanel.getComponent(3)).getText(); String eIn = ((JTextField)rsaInputPanel.getComponent(5)).getText(); String MIn = ((JTextField)rsaInputPanel.getComponent(7)).getText(); ArrayList<String> output = RSA.encrypt(BigInteger.valueOf(Long.parseLong(pIn)), BigInteger.valueOf(Long.parseLong(qIn)), BigInteger.valueOf(Long.parseLong(eIn)), BigInteger.valueOf(Long.parseLong(MIn))); String outputString = ""; for(int i = 0; i < output.size(); i++) outputString += output.get(i) + "\n"; // Set Output ((JTextArea)((JViewport)rsaOutputPane.getComponent(0)).getView()).setText(outputString); } }
c1ba6856-6d4a-4f21-a51a-47a85268be0d
public SpreadSheet(String[][] data) { super(new GridLayout(1,0)); String[] emptyLabels = new String[data[0].length]; for(int i = 0; i < emptyLabels.length; i++) emptyLabels[i] = " "; jT = new JTable(data, emptyLabels); TableModel model = new DefaultTableModel(data, emptyLabels) { public boolean isCellEditable(int row, int column) { return false; } }; jT.setModel(model); jT.setTableHeader(null); jT.setPreferredScrollableViewportSize(new Dimension(500,70)); jT.setFillsViewportHeight(true); add(new JScrollPane(jT)); }
23903e3c-df88-4775-a434-dbf882fcddb4
public boolean isCellEditable(int row, int column) { return false; }
afc16029-7252-47a7-96ca-f5e5b0659952
public static String shift(String inputString, int[] steps, boolean right) { String shiftedString = ""; for(int i = 0; i < inputString.length(); i++) shiftedString += addAndCheckWrap(inputString.charAt(i), (i+1), steps, right); return shiftedString; }
be148dc1-6b9e-4c28-809e-5b5a277cd979
private static char addAndCheckWrap(char c, int currentChar, int[] steps, boolean right) { int C = ((int)c); int loop; int mod = (currentChar % steps.length); if(mod == 0) loop = steps[steps.length-1]; else loop = steps[(mod-1)]; if(isAlphaNumericCharacter(c)) { if(right) { for(int i = 0; i < loop; i++) { C++; if(C == (((int)'Z') + 1)) C = ((int)'A'); else if(C == (((int)'z') + 1)) C = ((int)'a'); else if(C == (((int)'9') + 1)) C = ((int)'0'); } } else { for(int i = loop; i > 0; i--) { C--; if(C == (((int)'A') - 1)) C = ((int)'Z'); else if(C == (((int)'a') - 1)) C = ((int)'z'); else if(C == (((int)'0') - 1)) C = ((int)'9'); } } } return ((char)C); }
42bc4a10-1b8a-4a87-9eac-c8ac80741fd9
private static boolean isAlphaNumericCharacter(char c) { if((c >= ((int)'A') && c <= ((int)'Z')) || (c >= ((int)'a') && c <= ((int)'z')) || (c >= ((int)'0') && c <= ((int)'9'))) return true; return false; }
6f2eb0f9-50f9-4798-a5e4-a2ad8aa9e12b
public static ArrayList<String> encrypt(BigInteger p, BigInteger q, BigInteger e, BigInteger M) { ArrayList<String> output = new ArrayList<String>(); BigInteger n = p.multiply(q); BigInteger z = (p.subtract(BigInteger.valueOf(1))).multiply(q.subtract(BigInteger.valueOf(1))); output.add("p = " + p); output.add("q = " + q); output.add("e = " + e); output.add("M = " + M); output.add(""); output.add("n = (p)(q) = (" + p + ")(" + q + ") = " + n); output.add("z = (p-1)(q-1) = (" + p + "-1)(" + q + "-1) = " + z); output.add(""); BigInteger d = e.modInverse(z); output.add("d = gcd(e, z) = " + d); output.add(""); BigInteger enc = M; enc = enc.modPow(e, n); BigInteger dec = enc; dec = dec.modPow(d, n); output.add("Encrypted Output = " + enc); output.add("Decrypted Output (Check) = " + dec); return output; }
49b0fcfa-7def-4c45-999e-7ece078ebabe
public static ArrayList<String> encrypt(String key, String message) { keyBin = convert(key); messageBin = convert(message); generateKey(); generateMessage(); return generateList(); }